-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
53 lines (44 loc) · 1.35 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
const express = require('express');
const hbs = require('hbs');
const app = express();
const cookieParser = require('cookie-parser');
const home = require('./routers/home');
const login = require('./routers/login');
const port = process.env.PORT || 3000;
hbs.registerPartials(__dirname + '/views/layouts/partials');
app.use(cookieParser());
app.use(express.static('views/assets'));
hbs.registerHelper('getCurrentYear', () => {
return new Date().getFullYear();
});
app.set('view engine', 'hbs');
app.use('/', home);
app.use('/login', login);
// app.use((req, res, next) => {
//
// if (req.cookies === undefined) {
// let randomNumber = Math.random().toString();
// randomNumber = randomNumber.substring(2, randomNumber.length);
// res.cookies('cookieName', randomNumber, {maxAge:900000, httpOnly: true});
//
// console.log('cookie settled successfully');
// } else {
// console.log(`Cookie already exists ${JSON.stringify(req.cookies, undefined, 2)}`);
// }
//
// next();
// });
/**
Handling error 404 Page not found
*/
app.get('/*', (req, res) => {
res.status(400);
res.render(`layouts/pageNotFound.hbs`, {
url: req.url,
pageTitle: 'Page not found',
styleSheetPath: '/css/index.css'
});
});
app.listen(port, () => {
console.log(`Server is listening on port ${port}`);
});