-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
72 lines (62 loc) · 1.75 KB
/
server.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
67
68
69
70
71
72
var express = require("express");
var server = express();
var ARTICLES = require("./data/articles");
var PROJECTS = require("./data/projects");
server.set("view engine", "pug");
server.use("/css", express.static(__dirname + "/css"));
server.use("/images", express.static(__dirname + "/images"));
server.use(express.static(__dirname + "/scripts"));
server.use(express.static(__dirname + "/data"));
server.get("/", function (req, res) {
res.render("index", {
title: "Home",
stylesheet: "/css/index.css",
projects: PROJECTS,
articles: ARTICLES,
});
});
server.get("/about", function (req, res) {
res.render("about", {
title: "About",
stylesheet: "/css/page.css",
});
});
server.get("/blog", function (req, res) {
res.render("blog", {
title: "Blog",
stylesheet: "/css/projects.css",
articles: ARTICLES,
});
});
server.get("/blog/:blogPost", function (req, res) {
const blogPost = req.params.blogPost;
const blogTitle = ARTICLES.find((article) => article.link === `/blog/${blogPost}`).title;
res.render(`${blogPost}`, {
title: blogTitle,
stylesheet: "../css/page.css",
});
});
server.get("/projects", function (req, res) {
res.render("projects", {
title: "Projects",
stylesheet: "/css/projects.css",
projects: PROJECTS,
});
});
server.get("/projects/:projectPost", function (req, res) {
const projectPost = req.params.projectPost;
const projectTitle = PROJECTS.find(
(project) => project.link === `/projects/${projectPost}`
).title;
res.render(`${projectPost}`, {
title: projectTitle,
stylesheet: "../css/page.css",
});
});
let port = process.env.PORT;
if (port == null || port == "") {
port = 8000;
}
server.listen(port, function () {
console.log("Server is running on " + port);
});