-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
54 lines (44 loc) · 1.26 KB
/
index.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
import express from "express";
import path from "node:path";
import { fileURLToPath } from "node:url";
import ejsMate from "ejs-mate";
const app = express();
const port = process.env.PORT || 8000;
const __filename = fileURLToPath(import.meta.url);
const __dirname = path.dirname(__filename);
app.engine("ejs", ejsMate);
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
app.use(express.static(path.join(__dirname, "dist")));
app.use(express.static(path.join(__dirname, "public")));
app.get("/", (req, res) => {
res.render("index", { title: "Home", curYear: new Date().getFullYear() });
});
app.get("/about", (req, res) => {
res.render("about", { title: "About", curYear: new Date().getFullYear() });
});
app.get("/contact", (req, res) => {
res.render("contact", {
title: "Contact",
curYear: new Date().getFullYear(),
});
});
app.get("/courses", (req, res) => {
res.render("courses", {
title: "Courses",
curYear: new Date().getFullYear(),
});
});
app.use((req, res) => {
res
.status(404)
.render("404", {
title: "404 - Not Found",
curYear: new Date().getFullYear(),
});
});
app.listen(port, () => {
console.log(
`CIEFAL website running on port ${port} with URL http://127.0.0.1:${port}`
);
});