forked from cyclic-software/express-hello-world
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
93 lines (69 loc) · 2.43 KB
/
server.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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const { urlencoded } = require('body-parser');
const cookieParser = require('cookie-parser');
const express = require('express');
const expressEjsLayouts = require('express-ejs-layouts');
const port = process.env.PORT || 8000;
const db = require('./config/mongoose');
const flash = require('connect-flash');
const cMare = require('./config/middleware');
const app = express();
//-------------------------middlewares
app.use(urlencoded());
app.use(cookieParser());
//-------------------------sessions
const passport = require('passport');
const passportLocal = require('./config/passport-local-strategy');
const session = require('express-session');
//-------------------------sessions
//-------------------------mongoStore
const MongoStore = require('connect-mongo')(session);
//-------------------------mongoStore
//-------------------------views
//use assests
app.use(express.static('assests'));
app.use('/uploads', express.static(__dirname + '/uploads'))
//setting views
app.set('view engine','ejs');
app.set('views','./views');
//-------------------------views
//-------------------------express-ejs-layouts
//Using express-layouts and setting styles and scripts
app.use(expressEjsLayouts);
app.set("layout extractScripts", true);
app.set("layout extractStyles", true);
//-------------------------express-ejs-layouts
//-------------------------sessions
app.use(session({
name: 'todoAt',
secret: 'idontknowrightnowbutchangethisone',
saveUninitialized : false,
resave : false,
cookie: {
maxAge: (1000*60*100)
},
store: new MongoStore({
mongooseConnection : db,
autoRemove : 'disabled',
},(err) => {
err?console.log("Error:",err):console.log("Connected to MongoStore");
})
}));
app.use(passport.initialize());
app.use(passport.session());
app.use(passport.setAuthenticateUser);
//-------------------------sessions
//-------------------------flash
app.use(flash());
//-------------------------flash
//-------------------------custome Middleware
app.use(cMare.setFlash);
//-------------------------custome Middleware
//----------------------------------------------------------------
//-------------------------routes
app.use('/', require('./routes/router'));
//-------------------------routes
//-------------------------listen
app.listen(port, (err) => {
err ? console.log('Error',err) : console.log(`Server is up on port http://localhost:${port}/`);
});
//-------------------------listen