This repository has been archived by the owner on Aug 14, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
57 lines (49 loc) · 1.58 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'),
dotenv = require('dotenv').config(),
expressSanitizer = require('express-sanitizer'),
slashes = require('connect-slashes'),
helmet = require('helmet'),
app = express()
const dynamoConnect = require('./connections/dynamoConnect')
const authRoute = require('./router/authRoute'),
dashboardRoute = require('./router/dashboardRoute'),
redirectRoute = require('./router/redirectRoute'),
legalRoute = require('./router/legalRoute'),
createRoute = require('./router/createRoute'),
viewRoute = require('./router/viewRoute'),
indexRoute = require('./router/indexRoute'),
apiRoute = require('./router/apiRoute')
dynamoConnect()
app.set('view engine', 'ejs')
app.use(express.static('public', { extensions: ['html'] }))
app.use(express.json({ limit: '5mb' }))
app.use(express.urlencoded({ limit: '5mb', extended: true }))
app.use(expressSanitizer())
app.use(slashes(false))
app.use(
helmet({
contentSecurityPolicy: false,
})
)
app.use((err, req, res, next) => {
if (err.type === 'entity.too.large')
res.send(
'<p align="center">Please upload an image below the defined limit of 5 MB. <br> Click <a href="/create">here</a> to visit the upload page again.</p>'
)
else res.redirect('/')
})
app.use('/', indexRoute)
app.use('/auth', authRoute)
app.use('/create', createRoute)
app.use('/view', viewRoute)
app.use('/dashboard', dashboardRoute)
app.use('/legal', legalRoute)
app.use('/api', apiRoute)
app.use('/:slug', redirectRoute)
app.listen(process.env.PORT, () => {
console.log(
'Listening on port %d in %s mode',
process.env.PORT,
app.settings.env
)
})