-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
50 lines (39 loc) · 988 Bytes
/
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
const express = require("express");
const hbs = require("hbs");
const fs = require("fs");
const port = process.env.PORT || 3000;
const server = express();
hbs.registerPartials("./views/partials");
server.set("view engine", "hbs");
server.use((req, res, next) => {
const now = new Date().toString();
fs.appendFile("logs.txt", `${now}: ${req.method} - ${req.url}\n`);
next();
});
/*server.use((req, res, next) => {
res.render("maintenance.hbs")
});*/
server.use(express.static("./views"));
hbs.registerHelper("year", () => {
return new Date().getFullYear();
});
server.get("/", (req, res) => {
res.render("home.hbs", {
title: "Home",
message: "Welcome to ExpressJS!"
});
});
server.get("/about", (req, res) => {
res.render("about.hbs", {
title: "About"
});
});
server.get("/projects", (req, res) => {
res.render("projects.hbs", {
title: "Projects",
message: "Portfolio page here."
});
});
server.listen(port, () => {
console.log("Server is running...");
});