-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.js
More file actions
58 lines (42 loc) · 1.33 KB
/
server.js
File metadata and controls
58 lines (42 loc) · 1.33 KB
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
const express = require('express');
const handlebars = require('express3-handlebars').create({defaultLayout: 'main'});
const app = express();
app.engine('handlebars', handlebars.engine);
app.set('view engine', 'handlebars');
//app.set("views", "./app/views");
/* tells express that client asserts are
located in the public subfolders*/
app.use(express.static('public'));
var fortunes = [
"Conquer your fears or they will conquer you.",
"Rivers need springs.",
"Do not fear what you don't know.",
"You will have a pleasant surprise.",
"Whenever possible, keep it simple.",
];
// Home Page
app.get('/', function(req, res) {
//res.sendFile(`${__dirname}/app/views/home.handlebars`);
res.render('home');
});
// About Page
app.get('/about', function(req, res) {
var randomFortune =
fortunes[Math.floor(Math.random() * fortunes.length)];
res.render('about', { fortune: randomFortune});
});
// */
// 404 catch-all handler (middleware)
app.use(function(req, res, next){
res.status(404);
res.render('404');
});
// 500 error handler (middleware)
app.use(function(err, req, res, next) {
console.error(err.stack);
res.status(500);
res.render('500');
});
const listener = app.listen(process.env.PORT || 3002, () => {
console.log(`Your app is listening on port ${listener.address().port}`);
});