-
Notifications
You must be signed in to change notification settings - Fork 6
/
app.js
57 lines (50 loc) · 1.65 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
//Importing express and all other modules on top
const express = require("express");
const app = express();
const ejsMate = require("ejs-mate");
const path = require("path");
const methodOverride = require("method-override");
//User data modules
const userProjects = require("./userData/projecthelper.js");
//Setting up the view engine and it's directory
app.engine("ejs", ejsMate);
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
//All Express middleware/ Static files
app.use(express.urlencoded({ extended: true })); //req.body is parsed as a form
app.use(methodOverride("_method")); //Setting the query for method-override
app.use(express.static(path.join(__dirname, "public"))); //It will serve our static files
//Default Index/Home Route
//We don't need to add backslash when rendering view pages
app.get("/", async (req, res) => {
try {
//Fetch the incoming JSON data
const data = await JSON.stringify(userProjects);
//Parse it into JavaScript Object
const projects = await JSON.parse(data);
res.render("homepage", { projects });
} catch (e) {
console.log(e);
}
});
// Experience Route
app.get("/experience", (req, res) => {
res.render("experience");
});
// Experience Route
app.get("/project", async (req, res) => {
try {
//Fetch the incoming JSON data
const data = await JSON.stringify(userProjects);
//Parse it into JavaScript Object
const projects = await JSON.parse(data);
res.render("project", { projects });
} catch (e) {
console.log(e);
}
});
//Starting up server
const port = process.env.PORT || 3000;
app.listen(port, () => {
console.log(`Serving on the port: ${port}`);
});