-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathserver.js
54 lines (42 loc) · 1.34 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
const express = require('express');
const http = require('http');
const app = express()
const server = http.createServer(app);
const port = process.env.PORT || 3000
const path = require('path');
const healthRoute = require('./src/routes/healthRoute')
const webRoute = require('./src/routes/webRoutes')
const apiRoute = require('./src/routes/apiRoutes')
const swaggerUi = require('swagger-ui-express');
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerDefinition = require('./src/swagger/swaggerDefinition');
app.use(express.json());
const publicDirectoryPath = path.join(__dirname, '/public');
app.use(express.static(publicDirectoryPath));
const swaggerSpec = swaggerJsdoc(swaggerDefinition.options);
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
healthRoute.setup(app);
webRoute.setup(app);
apiRoute.setup(app);
app.get('/', function (req, res) {
res.redirect('/home');
})
app.use((req, res, next) => {
const error = new Error('Not Found');
error.status = 404;
next(error);
})
app.use((error, req, res, next) => {
res.status(error.status || 500);
res.json({
error: {
message: error.message
}
});
})
//Server Config
server.listen(port);
server.on('listening', function() {
console.log(`Express server started on port ${port} at localhost` );
});
module.exports = server