forked from OSU-CS290-Sp18/handlebars-templating
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
64 lines (56 loc) · 1.41 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
var path = require('path');
var express = require('express');
var exphbs = require('express-handlebars');
var peopleData = require('./peopleData');
var app = express();
var port = process.env.PORT || 3000;
app.engine('handlebars', exphbs({ defaultLayout: 'main' }));
app.set('view engine', 'handlebars');
app.use(express.static('public'));
app.get('/test', function (req, res, next) {
res.render('photoPage', {
name: "Kitty",
showDiv: false,
photos: [
{
photoURL: "http://placekitten.com/320/320?image=6",
caption: "A kitty"
},
{
photoURL: "http://placekitten.com/320/320?image=4",
caption: "A kitty"
},
{
photoURL: "http://placekitten.com/320/320?image=2",
caption: "A kitty"
},
{
photoURL: "http://placekitten.com/320/320?image=3",
caption: "A kitty"
}
]
});
});
app.get('/people', function (req, res, next) {
res.status(200).render('peoplePage', {
people: peopleData
});
});
// var availablePeople = [
// 'beyonce',
// 'einstein',
// 'luke',
// 'marie',
// 'ta-nehisi'
// ];
app.get('/people/:person', function (req, res, next) {
var person = req.params.person.toLowerCase();
if (peopleData[person]) {
res.status(200).render('photoPage', peopleData[person]);
} else {
next();
}
});
app.listen(port, function () {
console.log("== Server listening on port", port);
})