summaryrefslogtreecommitdiff
path: root/src/app.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/app.ts')
-rwxr-xr-xsrc/app.ts30
1 files changed, 20 insertions, 10 deletions
diff --git a/src/app.ts b/src/app.ts
index 0708081..7ed535c 100755
--- a/src/app.ts
+++ b/src/app.ts
@@ -1,6 +1,6 @@
import express from "express";
-import hbs from "express-handlebars";
import cookieParser from "cookie-parser";
+import { create as createHandlebars, ExpressHandlebars } from "express-handlebars";
import routes from "./routes.js";
import frontend from "./routes/frontend.js";
@@ -9,29 +9,27 @@ 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 {
activityPubContentType,
alternateActivityPubContentType,
} from "./lib/activitypub.js";
+import { EmailService } from "./lib/email.js";
+import getConfig from "./lib/config.js";
const app = express();
+const config = getConfig();
-app.locals.sendEmails = initEmailService();
-
-// View engine //
-const hbsInstance = hbs.create({
+const hbsInstance = createHandlebars({
defaultLayout: "main",
partialsDir: ["views/partials/"],
layoutsDir: "views/layouts/",
helpers: {
plural: function (number: number, text: string) {
- var singular = number === 1;
+ const singular = number === 1;
// If no text parameter was given, just return a conditional s.
if (typeof text !== "string") return singular ? "" : "s";
// Split with regex into group1/group2 or group1(group3)
- var match = text.match(/^([^()\/]+)(?:\/(.+))?(?:\((\w+)\))?/);
+ const match = text.match(/^([^()\/]+)(?:\/(.+))?(?:\((\w+)\))?/);
// If no match, just append a conditional s.
if (!match) return text + (singular ? "" : "s");
// We have a good match, so fire away
@@ -41,11 +39,23 @@ const hbsInstance = hbs.create({
match[1] + (match[3] || "s")
); // Plural case: 'bagel(s)' or 'bagel' --> bagels
},
- json: function (context: any) {
+ 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);