summaryrefslogtreecommitdiff
path: root/src/app.ts
diff options
context:
space:
mode:
authorRaphael Kabo <raphaelkabo@hey.com>2023-10-06 12:34:36 +0100
committerRaphael Kabo <raphaelkabo@hey.com>2023-10-06 12:34:36 +0100
commitf80e509895b7b2c1d716ac276977b7165a13c192 (patch)
tree58220155d7ccdd8e47fca8ab9df087af5b80cc2b /src/app.ts
parentbd9fb237fa5bcc076d4c6f3bf8ff748df63515e4 (diff)
Typescript migration
Diffstat (limited to 'src/app.ts')
-rwxr-xr-xsrc/app.ts44
1 files changed, 44 insertions, 0 deletions
diff --git a/src/app.ts b/src/app.ts
new file mode 100755
index 0000000..32e89b6
--- /dev/null
+++ b/src/app.ts
@@ -0,0 +1,44 @@
+import express from "express";
+import routes from "./routes.js";
+import hbs from "express-handlebars";
+
+const app = express();
+
+// View engine //
+const hbsInstance = hbs.create({
+ defaultLayout: "main",
+ partialsDir: ["views/partials/"],
+ layoutsDir: "views/layouts/",
+ helpers: {
+ plural: function (number: number, text: string) {
+ var 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+)\))?/);
+ // If no match, just append a conditional s.
+ if (!match) return text + (singular ? "" : "s");
+ // We have a good match, so fire away
+ return (
+ (singular && match[1]) || // Singular case
+ match[2] || // Plural case: 'bagel/bagels' --> bagels
+ match[1] + (match[3] || "s")
+ ); // Plural case: 'bagel(s)' or 'bagel' --> bagels
+ },
+ },
+});
+app.engine("handlebars", hbsInstance.engine);
+app.set("view engine", "handlebars");
+app.set("hbsInstance", hbsInstance);
+
+// Static files //
+app.use(express.static("public"));
+
+// Body parser //
+app.use(express.json({ type: "application/activity+json" })); // support json encoded bodies
+app.use(express.urlencoded({ extended: true }));
+
+// Router //
+app.use("/", routes);
+
+export default app;