-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
77 lines (62 loc) · 1.43 KB
/
index.js
File metadata and controls
77 lines (62 loc) · 1.43 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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const express = require("express");
const app = express();
const exphbs = require("express-handlebars");
const PORT = 3000;
const session = require('express-session');
const router = require('./router.js');
const db = require('./models/index.js');
// support parsing of application/json type post data
app.use(express.json());
//support parsing of application/x-www-form-urlencoded post data
app.use(express.urlencoded({ extended: true }));
app.use(express.static("public"));
const hbs = exphbs.create({
extname: ".hbs",
helpers: {
ifCond: function (v1, v2, options) {
if (v1 === v2) {
return options.fn(this);
}
return options.inverse(this);
}
}
});
app.engine(".hbs", hbs.engine);
app.set("view engine", ".hbs");
app.use(session({
name:'CabBookingApp-User-Session',
secret:'asdfgthyjuik679843465',
resave:false,
saveUninitialized:true,
cookie:{
httpOnly:true,
maxAge:12000000,
path:'/',
samesite:true,
secure:false
}
})
)
app.use('/', router);
app.get("/sessionTest" , function(req,res){
if(req.session.user){
return res.send({
status : true ,
data : req.session.user
})
}
return res.send({
status:false
})
})
db.connect()
.then( function(){
app.listen(PORT, function(req, res){
console.log("Application is running on PORT: ",PORT);
})
}
)
.catch(function(error){
console.log("Failed to connect to database ",error);
}
)