-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
52 lines (33 loc) · 1.1 KB
/
index.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
const dotenv = require('dotenv');
const express = require('express');
const hbs = require('hbs');
const session = require('express-session');
const app = express() //initializing an express server and passing to app
app.set('view engine', '.hbs');
hbs.registerPartials(__dirname + '/views/partials');
dotenv.config();
port = process.env.PORT;
hostname = process.env.HOSTNAME;
app.use(express.static('public'));
app.use(express.urlencoded({extended: true}));
app.use(session({
'secret': 'ccapdev-session',
'resave': false,
'saveUninitialized': false,
}));
const indexRouter = require('./routes/router');
app.use('/', indexRouter);
app.use(function(req, res){
var details = {};
if (req.session.userName) {
details.flag = true;
details.userName = req.session.userName;
}
else
details.flag = false;
res.render('error', details);
})
app.listen(port, hostname, function() {
console.log('Server running at: ');
console.log('http://' + hostname + ':' + port);
}); //bind server to the port