-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (29 loc) · 987 Bytes
/
index.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
const url = require("url");
const express = require("express");
const swaggerUi = require("swagger-ui-express");
const swaggerSpec = require("./swagger");
const api = require("./api");
const flatCacheMiddleware = require("./middlewares/flatCacheMiddleware");
const PORT = process.env.PORT || 8080;
const app = express();
app.use("/api", api(express.Router()));
app.use("/", swaggerUi.serve);
app.get("/", swaggerUi.setup(swaggerSpec));
const createServerInfo = server => {
let serverInfo = ({ address, port } = server.address());
let hostForUrl = serverInfo.address;
if (serverInfo.address === "" || serverInfo.address === "::") {
hostForUrl = "localhost";
}
serverInfo.url = url.format({
protocol: "http",
hostname: hostForUrl,
port: serverInfo.port
});
return serverInfo;
};
const server = app.listen(PORT, () => {
const serverInfo = createServerInfo(server);
console.log(`🚀 Server ready at ${serverInfo.url}`);
});
module.exports = server;