-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
66 lines (56 loc) · 1.42 KB
/
app.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
const express = require("express");
const exphbs = require("express-handlebars");
const path = require("path");
const app = express();
const port = process.env.PORT || 3000;
// Configure Handlebars
const hbs = exphbs.create({
defaultLayout: "main",
extname: ".handlebars",
// Create custom helper for active navigation
helpers: {
isActive: function (current, page) {
return current === page ? "active" : "";
},
},
});
app.engine("handlebars", hbs.engine);
app.set("view engine", "handlebars");
// Serve static files
app.use("/assets", express.static(path.join(__dirname, "assets")));
// Custom middleware to remove .html extension
app.use((req, res, next) => {
if (req.path.endsWith(".html")) {
const newPath = req.path.slice(0, -5);
return res.redirect(301, newPath);
}
next();
});
// Routes
app.get("/", async (req, res) => {
res.render("index", {
title: "DevFest Lagos 2024 | Olympus",
currentPage: "index",
});
});
app.get("/login", (req, res) => {
res.render("login", {
title: "DevFest Lagos 2024 | Olympus",
currentPage: "login",
layout: "auth",
});
});
app.get("/404", (req, res) => {
res.status(404).render("404", {
title: "404 - Page Not Found",
currentPage: "404",
layout: "auth",
});
});
app.use((req, res) => {
res.redirect("/404");
});
// Start server
app.listen(port, () => {
console.log(`Server running at http://localhost:${port}`);
});