summaryrefslogtreecommitdiff
path: root/src/app.js
diff options
context:
space:
mode:
authorRaphael <raphaelkabo@hey.com>2023-05-12 17:03:13 +0100
committerGitHub <noreply@github.com>2023-05-12 17:03:13 +0100
commit67cf89fd0cfdf56c7e6d6d9bdf93d95d679ce2a1 (patch)
treec66bdf874a210997cd1d84942101773ba0175b20 /src/app.js
parenta75aad783c117aaef2ec19b6b434be0f0d7e57de (diff)
parent50688f573054f60aa7594672615f11713173c147 (diff)
Merge pull request #95 from lowercasename/typescript
Migrate to TypeScript and PNPM
Diffstat (limited to 'src/app.js')
-rwxr-xr-xsrc/app.js53
1 files changed, 53 insertions, 0 deletions
diff --git a/src/app.js b/src/app.js
new file mode 100755
index 0000000..4a2137e
--- /dev/null
+++ b/src/app.js
@@ -0,0 +1,53 @@
+const express = require("express");
+const path = require("path");
+const session = require("express-session");
+const cors = require("cors");
+const routes = require("./routes");
+const hbs = require("express-handlebars");
+const bodyParser = require("body-parser");
+
+const app = express();
+
+// Configuration //
+
+//app.use(cors());
+//app.use(bodyParser.json());
+//app.use(session({ secret: 'slartibartfast', cookie: { maxAge: 60000 }, resave: false, saveUninitialized: false }));
+
+// View engine //
+const hbsInstance = hbs.create({
+ defaultLayout: "main",
+ partialsDir: ["views/partials/"],
+ layoutsDir: "views/layouts/",
+ helpers: {
+ plural: function (number, text) {
+ 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"));
+
+// Router //
+app.use(bodyParser.json({ type: "application/activity+json" })); // support json encoded bodies
+app.use(bodyParser.urlencoded({ extended: true }));
+app.use("/", routes);
+
+module.exports = app;