-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
84 lines (70 loc) · 2.38 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
if (process.env.NODE_ENV !== 'production') {
require('dotenv').config()
}
const express = require('express')
const compression = require('compression')
const app = express()
app.use(compression({
level: 6
}))
app.use(express.static('public', {
maxAge: '7d'
}))
const favicon = require('serve-favicon')
const expressLayouts = require('express-ejs-layouts')
const methodOverride = require('method-override')
const bodyParser = require('body-parser')
const filter = require('content-filter')
const mongoSanitize = require('express-mongo-sanitize')
const flash = require('express-flash')
const session = require('express-session')
const passport = require('passport')
const indexRouter = require('./routes/index')
const userRouter = require('./routes/user')
const adminRouter = require('./routes/admin')
const codesRouter = require('./routes/codes')
const productsRouter = require('./routes/products')
const requestRouter = require('./routes/request')
const contactRouter = require('./routes/contact')
app.set('view engine', 'ejs')
app.set('views', __dirname + '/views')
app.set('layout', 'layouts/layout')
app.use(favicon(__dirname + '/public/images/favicon.ico'))
app.use(expressLayouts)
app.use(methodOverride('_method'))
app.use(bodyParser.urlencoded({ limit: '10mb', extended: false }))
app.use(bodyParser.json())
const blackList = ['$','{','&&','||']
const options = {
urlBlackList: blackList,
bodyBlackList: blackList,
methodList:['GET', 'DELETE'],
urlMessage: 'A forbidden expression has been found in the URL',
bodyMessage: 'A forbidden expression has been found in the form data'
}
app.use(filter(options))
app.use(mongoSanitize())
app.use(flash())
app.use(session({
secret: process.env.SESSION_SECRET,
resave: false,
saveUninitialized: false
}))
app.use(passport.initialize())
app.use(passport.session())
const mongoose = require('mongoose')
mongoose.connect(process.env.DATABASE_URL, { useNewUrlParser: true })
const db = mongoose.connection
db.on('error', error => console.error(error))
db.once('open', () => console.log('Connected to Mongoose'))
app.use('/', indexRouter)
app.use('/', userRouter)
app.use('/admin', adminRouter)
app.use('/codes', codesRouter)
app.use('/products', productsRouter)
app.use('/request', requestRouter)
app.use('/contact', contactRouter)
app.use(function (req, res, next) {
res.status(404).send()
})
app.listen(process.env.PORT || 3000)