-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.js
63 lines (54 loc) · 1.69 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
55
56
57
58
59
60
61
62
63
const express = require('express');
const http = require('http');
const app = express()
const server = http.createServer(app);
const port = process.env.PORT || 3000
const healthRoute = require('./src/routes/health-route')
const inventoryRoute = require('./src/routes/inventory-route')
const swaggerUi = require('swagger-ui-express');
const swaggerJsdoc = require('swagger-jsdoc');
const swaggerDefinition = {
"openapi": '3.0.1',
"info": {
"title": "Inventory Service with Kafka test",
"description": "API for updating the Inventory Service.",
"version": "1.0.0"
},
host: `localhost:${port}`, // Host (optional)
basePath: '/', // Base path (optional)
};
// Options for the swagger docs
const options = {
// Import swaggerDefinitions
swaggerDefinition,
// Path to the API docs
// Note that this path is relative to the current directory from which the Node.js is ran, not the application itself.
apis: ['./src/routes/*', './src/parameters/*']
};
const swaggerSpec = swaggerJsdoc(options);
app.use(express.json());
app.use('/api-docs', swaggerUi.serve, swaggerUi.setup(swaggerSpec));
app.get('/', function (req, res) {
res.redirect('/api-docs')
})
healthRoute.setup(app);
inventoryRoute.setup(app);
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(3000);
server.on('listening', function() {
console.log('Express server started on port %s at %s', server.address().port, server.address().address);
});
module.exports = server