-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
42 lines (34 loc) · 857 Bytes
/
app.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
// Express
const express = require("express");
const cors = require('cors');
const app = express();
const port = 80;
// API
const api = require("./api");
// Swagger
const swaggerUI = require("swagger-ui-express");
const swaggerSpecifications = require("./swagger/swagger.json");
// CORS
app.use(cors());
// Load APIs
api.boot(app);
// Express Configuration
app.listen(port);
// Expose Swagger
app.use("/", swaggerUI.serve, swaggerUI.setup(swaggerSpecifications));
// Internal Error Handler
app.use(function (error, request, response, next) {
response.status(500).send({
status: 500,
message: "error",
data: error.message
});
});
// Not Found Error Handler
app.use(function (request, response, next) {
response.status(404).send({
status: 404,
message: "error",
data: "not found"
});
});