-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathserver.js
32 lines (26 loc) · 950 Bytes
/
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
const express = require('express')
const methodOverride = require('method-override')
const swaggerUi = require('swagger-ui-express')
const openApiDocumentation = require('./openapi.json')
const indexRouter = require('./routes/index')
const apiRouter = require('./routes/api')
const server = express()
const port = process.env.PORT || 8080
server.use(express.json({limit: '50mb'}));
server.use(express.urlencoded({limit: '50mb', extended: false}));
server.use('/', indexRouter)
server.use('/api', apiRouter)
server.use(methodOverride())
server.use(logErrors)
server.use(errorHandler)
server.use('/api-docs', swaggerUi.serve, swaggerUi.setup(openApiDocumentation));
server.listen(port, () => {
console.log("xatkit-nlp.js-server running on port", port)
})
function logErrors (err, req, res, next) {
console.error(err.stack)
next(err)
}
function errorHandler (err, req, res, next) {
res.status(500).json({ message: err.message })
}