-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
57 lines (44 loc) · 1.27 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 session = require('express-session')
var MemoryStore = require('memorystore')(session)
const cookie = require('cookie-parser')
const ejs = require('ejs')
const bodyParser = require('body-parser')
const flash = require('connect-flash')
const passport = require('passport')
const csrf = require('csurf')
const app = express()
// CONNECT DATABASE
const connectDB = require('./database/connection')
connectDB
require('dotenv').config({ path: "./config/config.env" });
const PORT = process.env.PORT || 8080
app.use(bodyParser.urlencoded({extended: false}))
app.set('view engine', 'ejs')
// SETUP COOKIE
app.use(cookie(process.env.SECRET_KEY))
app.use(session({
secret: process.env.SECRET_KEY,
store: new MemoryStore({
checkPeriod: 86400000 // prune expired entries every 24h
}),
resave: false,
saveUninitialized: true
}))
app.use(csrf())
// SET UP PASSPORT
app.use(passport.initialize())
app.use(passport.session())
// SET UP FLASH
app.use(flash())
app.use((req, res, next)=>{
res.locals.error = req.flash('error')
next()
})
// INITIALIZE PUBLIC FOLDER
app.use(express.static('public'))
// USE ROUTES
app.use(require('./controllerS/routes.js'));
app.listen(PORT, ()=>{
console.log('Server running on ' + PORT)
})