-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
36 lines (31 loc) · 1.07 KB
/
app.js
File metadata and controls
36 lines (31 loc) · 1.07 KB
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
const express = require('express')
const bodyParser = require('body-parser')
const config = require('./config')
const setUpRoutes = require('./routes-bootstrap')
const fileUpload = require("express-fileupload")
var cors = require('cors')
const app = express()
app.use(cors())
app.use(bodyParser.json())
app.use(
bodyParser.urlencoded({
extended: true,
})
)
app.use(fileUpload({
limits: {
fileSize: config.MEDIA_SIZE_LIMIT
},
limitHandler: (req, res) => {
const errorMessage = `Your file size exceeds ${config.MEDIA_SIZE_LIMIT / 1024 / 1024}MB. Please try again with a smaller file.`
res.status(400).json({ message: errorMessage })
// the below line is used to check this property in controller.
// The reason is that lib doesn't stop execution after custom limitHandler
// see more details: https://github.com/richardgirges/express-fileupload/issues/238
req.shouldAbort = true
}
}))
setUpRoutes(app)
app.listen(config.SERVER_PORT, () => {
console.log(`Listening on port ${config.SERVER_PORT}...`)
})