-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (44 loc) · 1.63 KB
/
app.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
const express = require('express');
const mongoose = require('mongoose');
const router = express.Router();
const csrf = require('csurf');
const cookieParser = require('cookie-parser');
const expressSession = require('express-session');
const MemoryStore = require('memorystore')(expressSession)
const passport = require('passport');
const flash = require('connect-flash');
const path=require('path');
const app = express();
const multer=require('multer')
app.use(express.static(path.join(__dirname, 'public')));
app.set('view engine', 'ejs');
app.set('views', __dirname + '/views',);
app.use(express.urlencoded({ extended: true }));
const mongoURI = require('./config/monkoKEY');
mongoose.connect(mongoURI, { useNewUrlParser: true, useUnifiedTopology: true },).then(() => console.log("Connected !"),);
app.use(cookieParser());
var csrfProtection = csrf({ cookie: false });
app.use(expressSession({
secret: "random",
resave: true,
saveUninitialized: true,
// setting the max age to longer duration
maxAge: 24 * 60 * 60 * 1000,
store: new MemoryStore(),
}));
app.use(csrf());
app.use(flash());
app.use(passport.initialize());
app.use(passport.session());
app.use(function (req, res, next) {
//var token = req.csrfToken();
// res.cookie('XSRF-TOKEN', token);
// res.locals.csrfToken = token;
res.locals.success_messages = req.flash('success_messages');
res.locals.error_messages = req.flash('error_messages');
res.locals.error = req.flash('error');
next();
});
app.use(require('./controller/routes.js'));
const PORT = process.env.PORT || 2378;
app.listen(PORT, () => console.log("Server Started At " + PORT));