-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
56 lines (45 loc) · 1.35 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
require('dotenv').config()
const path = require('path')
const express = require('express')
const session = require('express-session')
const expressLayout = require('express-ejs-layouts')
const passport = require('passport')
const cookieParser = require('cookie-parser')
const MongoStore = require('connect-mongo')
const connectDB = require('./server/config/db')
const mainRouter = require('./server/routes/main')
const adminRouter = require('./server/routes/admin')
const helmet = require('helmet')
const compression = require('compression')
const app = express()
const PORT = process.env.PORT || 3000
// Connect to DB
connectDB()
app.use(express.json())
app.use(express.urlencoded({ extended: true }))
app.use(cookieParser())
app.use(helmet())
app.use(compression())
app.use(express.static(path.join(__dirname, 'public')))
app.use(
session({
secret: process.env.SECRET,
resave: false,
saveUninitialized: true,
store: MongoStore.create({
mongoUrl: process.env.MONGODB_URI,
}),
cookie: { expires: new Date(Date.now() + 3600000) },
})
)
app.use(passport.session())
// Template Engine
app.use(expressLayout)
app.set('layout', path.join(__dirname, 'views/layouts/main'))
app.set('view engine', 'ejs')
// Use routes
app.use('/', mainRouter)
app.use('/admin', adminRouter)
app.listen(PORT, () => {
console.log(`Listening on PORT ${PORT}`)
})