forked from kalviumcommunity/compilerd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
53 lines (46 loc) · 1.24 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
require('./envloader')()
const express = require('express')
const app = express()
const cors = require('cors')
const compression = require('compression')
const helmet = require('helmet')
const baseRouter = require('./router.js')
const morgan = require('morgan')
const PORT = process.env.PORT || 3000
const { respond, l } = require('./loader.js').helpers
require('./loader.js').loadDependency(app)
/* Middlewares */
app.use(express.json())
app.use((err, req, res, next) => {
if (err instanceof SyntaxError && err.status === 400 && 'body' in err) {
return respond(res, 400, { message: 'Invalid JSON found' })
}
next()
})
// Log all api requests
app.use(
morgan(
'REQUEST [:date[clf]] ":method :url HTTP/:http-version" :status :user-agent',
{
immediate: true,
skip: function (req) { return (req.path === '/api/') },
},
),
)
app.use(
express.urlencoded({
extended: true,
limit: '2mb',
parameterLimit: 1000000,
}),
)
app.use(compression())
app.use(helmet())
app.use(cors())
app.use('/api/', baseRouter)
app.get('/', (req, res) => {
return res.send('Compiler is up and working')
})
app.listen(PORT, () => {
l.info(`Server started at port: ${PORT}`)
})