-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
79 lines (56 loc) · 1.69 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
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
78
79
const express= require('express');
const port =8080;
const HOST = '0.0.0.0';
const app=express();
const path= require('path');
app.use(express.urlencoded());
const passport= require('passport');
const passportLocal= require('./config/passport-local-strategy');
const mongoose= require('./config/mongoose');
const flash= require('connect-flash');
const session= require('express-session');
const MongoStore= require('connect-mongo')(session);
const db = require('./config/mongoose');
const Product= require('./models/products');
const customMware= require('./config/middleware');
const http = require('http');
// app.use(cookieParser());
app.use(session({
secret:'abcdefghijk',
saveUninitialized:'false',
resave:'false',
cookie:{
maxAge:(1000 * 60 * 100)
},
store:new MongoStore(
{
mongooseConnection:db,
autoRemove: 'disabled'
},
function(err){
console.log(err || 'connect-mongoose setup OK')
}
)
}));
app.use(express.static('./assets'));
app.use(express.json());
//global middleware to pass the session variable to front end part
app.use((req,res,next) =>{
res.locals.session= req.session;
next();
})
app.set('views','./views');
app.set('views',path.join(__dirname,'views'));
app.set('view engine','ejs');
app.use(passport.initialize());
app.use(passport.session());
app.use(passport.setAuthenticateduser);
app.use(flash());
app.use(customMware.setFlash);
app.use('/',require('./routes/index'));
app.listen( port, HOST ,function(err){
if(err){
console.log('server will not run on this port:',port );
}
console.log('server is running on port:',port);
})