-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
97 lines (79 loc) · 2.29 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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
if (process.env.NODE_ENV != "production") {
require('dotenv').config();
}
const express = require('express');
const port = process.env.PORT || 8000;
const app = express();
const expressLayouts = require('express-ejs-layouts');
if (process.env.NODE_ENV != "production") {
require('dotenv').config();
}
const db = require('./config/mongoose')
const bodyParser = require("body-parser");
// to parse the body into json format
app.use(
bodyParser.urlencoded({
extended: true,
})
);
const customMware = require('./config/middleware');
app.use(express.static('./assets'));
//TODO -> create express-session
const cookieParser = require('cookie-parser');
const session = require('express-session');
app.use(cookieParser());
const MongoStrore = require('connect-mongo');
app.use(session({
name: 'TODO',
secret: process.env.secret,
saveUninitialized: false,
resave: false,
cookie: {
maxAge: (604800000)
},
store: MongoStrore.create(
{
mongoUrl: process.env.mogourl,
autoRemove: 'disabled'
},
function (err) {
console.log(err || 'connect-mongodb setup ok');
}
)
}))
//setting layout
app.set('layout extractStyles', true)
app.set('layout extractScripts', true)
app.use(expressLayouts);
//setup view engine
app.set('view engine', 'ejs');
app.set('views', './views');
// setting up passport with local startegy
const passport = require('passport')
const passportLocal = require('./config/passport-local-strategy');
const passportGoogle = require('./config/passport-google-oauth2-strategy');
app.use(passport.initialize());
app.use(passport.session());
app.use(passport.setAuthenticatedUser) // middleware to access the authenticated user from locals for views
function visitor(req, res, next) {
console.log(req.ip, req.path, req.method)
next()
}
app.use(visitor);
//setting up flash
const flash = require('connect-flash');
app.use(flash());
app.use(customMware.setFlash);
// app.use((error,req,res,next)=>{
// console.log(error);
// res.send(error)
// next();
// })
//use express router
app.use('/', require('./routes/index'));
app.listen(port, function (err) {
if (err) {
console.log("Server not setup", err);
}
console.log('Server is up and running at port:', port);
})