-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
102 lines (85 loc) · 2.23 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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
var fs = require('fs');
var path = require('path');
var express = require('express');
var app = express();
var exphbs = require('express-handlebars');
const { type } = require('os');
const { EDESTADDRREQ } = require('constants');
var port = process.env.PORT || 3000;
var projects = require('./JSONs/projectsList.json');
var positions = require('./JSONs/positionsList.json');
var degrees = require('./JSONs/degreesList.json');
app.engine('handlebars', exphbs({defaultLayout: 'main'}));
app.set('view engine', 'handlebars');
app.use(express.json());
app.use(express.static('public'));
app.get('/', function(req, res, next) {
res.status(301).redirect('/portfolio/');
next();
});
app.get('/portfolio/', function(req, res, next) {
res.status(200).render('portfolio', {projects, portfolio: true});
});
app.get('/experience/', function(req, res, next) {
res.status(200).render('experience', {positions, experience: true});
});
app.get('/education/', function(req, res, next) {
res.status(200).render('education', {degrees, education: true});
});
app.get('/summary/', function(req, res, next) {
res.status(200).render('summary', {summary: true});
});
app.get('/portfolio/:proj/', function(req, res, next) {
var proj = req.params.proj;
if (projects[proj]) {
res.status(301).redirect('/:proj/demo/');
next();
}
else {
next();
}
});
app.get('/portfolio/:proj/demo', function(req, res, next) {
var proj = req.params.proj;
if(projects[proj]) {
res.status(200).render('projectdemo', projects[proj]);
}
else {
next();
}
});
app.get('/portfolio/:proj/code', function(req, res, next) {
var proj = req.params.proj;
if(projects[proj]) {
res.status(200).render('password');
}
else {
next();
}
});
app.post('/portfolio/:proj/code/sendPwd', function(req, res, next) {
var proj = req.params.proj;
if (req.body && req.body.password) {
//actually checking pwd
if (req.body.password == "####") {
if (projects[proj]) {
res.status(200).render('projectcode', projects[proj]);
}
else {
next();
}
}
else {
res.status(401).send();
}
}
else {
res.status(400);
}
});
app.get('*', function (req, res) {
res.status(404).render('404');
});
app.listen(port, function () {
console.log("== Server is listening on port", port);
});