-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.mjs
65 lines (56 loc) · 1.26 KB
/
app.mjs
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
import express from "express";
import methodOverride from "method-override";
import compression from "compression";
import errorHandler from "errorhandler";
import path from "path";
import morgan from "morgan";
const __dirname = path.resolve();
const port = process.env.PORT || 9000;
const app = express();
// Express configs
app.set("views", path.join(__dirname, "views"));
app.set("view engine", "pug");
// Middlewares
app.use(
compression({
level: 9
})
);
app.use(methodOverride());
app.use(errorHandler());
app.use(express.static(path.join(__dirname, "public")));
app.use(morgan("dev"));
// Home page
app.get("/", (req, res) => {
res.render("pages/home", {
title: "Home"
});
});
// About page
app.get("/about", (req, res) => {
res.render("pages/about", {
title: "About"
});
});
// Portfolio page
app.get("/portfolio", (req, res) => {
return res.render("pages/portfolio", {
title: "Portfolio"
});
});
// Contact page
app.get("/contact", (req, res) => {
return res.render("pages/contact", {
title: "Contact"
});
});
// works page
app.get("/works/:name", (req, res) => {
const name = req.params.name;
res.render(`pages/works/${name}`, {
title: `${name}`
});
});
app.listen(port, () => {
console.log(`Server started at ${port}`);
});