diff options
author | INOUE Daisuke <inoue.daisuke@gmail.com> | 2025-05-03 22:38:45 +0900 |
---|---|---|
committer | INOUE Daisuke <inoue.daisuke@gmail.com> | 2025-05-03 22:38:45 +0900 |
commit | 861fff32a70c5631e3061fe3d68fbe83c9d9bc3b (patch) | |
tree | 6d677e86b42c78de3d72c78286db0481873123d5 /src/app.ts | |
parent | d901c09ff606d9298fbefd7ecefb6dd3bfe22ac2 (diff) | |
parent | 69f75005303d634b9208c23068655385734f4d3a (diff) |
Merge branch 'main' into feature/localization-again
Diffstat (limited to 'src/app.ts')
-rwxr-xr-x | src/app.ts | 33 |
1 files changed, 23 insertions, 10 deletions
@@ -1,7 +1,6 @@ import express from "express"; -import hbs, { ExpressHandlebars } from "express-handlebars"; -import Handlebars from 'handlebars'; import cookieParser from "cookie-parser"; +import { create as createHandlebars, ExpressHandlebars } from "express-handlebars"; import i18next from "i18next"; import Backend from "i18next-fs-backend"; import { LanguageDetector, handle } from 'i18next-http-middleware'; @@ -24,18 +23,17 @@ import event from "./routes/event.js"; import group from "./routes/group.js"; import staticPages from "./routes/static.js"; import magicLink from "./routes/magicLink.js"; - -import { initEmailService } from "./lib/email.js"; import { getI18nHelpers } from "./helpers.js"; import { activityPubContentType, alternateActivityPubContentType, } from "./lib/activitypub.js"; import moment from "moment"; +import { EmailService } from "./lib/email.js"; +import getConfig from "./lib/config.js"; const app = express(); - -app.locals.sendEmails = initEmailService(); +const config = getConfig(); // function to construct __dirname with ES module const getLocalesPath = () => { @@ -101,23 +99,38 @@ async function initializeApp() { // }); // View engine // - const hbsInstance: ExpressHandlebars = hbs.create({ + const hbsInstance = createHandlebars({ defaultLayout: "main", partialsDir: ["views/partials/"], layoutsDir: "views/layouts/", helpers: { - json: function (context: any) { - return JSON.stringify(context); - }, // add i18next helpers ...getI18nHelpers(), plural: function (key: string, count: number, options: any) { // Register the plural helper const translation = i18next.t(key, { count: count }); return translation; + }, + json: function (context: object) { + return JSON.stringify(context); } }, }); + const emailService = new EmailService(config, hbsInstance); + emailService.verify(); + + app.use((req: express.Request, _: express.Response, next: express.NextFunction) => { + req.hbsInstance = hbsInstance; + req.emailService = emailService; + next() + return + }) + + // View engine // + app.engine("handlebars", hbsInstance.engine); + app.set("view engine", "handlebars"); + app.set("hbsInstance", hbsInstance); + // calling i18nextHelper if (typeof handlebarsI18next === 'function') { handlebarsI18next(hbsInstance.handlebars, i18next); |