-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathserver.js
41 lines (32 loc) · 1021 Bytes
/
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
var path = require('path');
var express = require('express');
var exphbs = require('express-handlebars');
var peopleData = require('./peopleData');
var app = express();
app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
app.set('view engine', 'handlebars');
// console.log("==peopleData:", peopleData);
app.get('/', function (req, res) {
res.render('homePage');
});
app.get('/people', function (req, res) {
res.status(200).sendFile(path.join(__dirname, 'public', 'people.html'));
});
app.get('/people/:personId', function(req, res, next) {
var personId = req.params.personId;
if (peopleData[personId]) {
var person = peopleData[personId];
res.status(200).render('personPage', person);
}
else {
next();
}
});
app.use(express.static('public'));
app.use('*', function (req, res) {
// res.status(404).sendFile(path.join(__dirname, 'public', '404.html'));
res.status(404).render('404');
});
app.listen(8000, function () {
console.log("== Server listening on port 8000");
});