-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
40 lines (31 loc) · 932 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
38
39
40
const express = require("express");
const morgan = require("morgan");
require("dotenv").config();
const connectToDb = require("./src/database/db");
const router = require("./src/routes");
const cors = require("cors");
const config = require("./src/config");
const logger = require("./logger/logger");
const swaggerFile = require("./swagger_output.json");
const swaggerUi = require('swagger-ui-express')
const app = express();
app.use(express.json());
const whitelist = [
"http://localhost:8080",
"http://localhost:8001",
"http://localhost:3000",
"http://localhost:3001",
];
app.use(cors(whitelist));
if (config.nodeEnv !== "production") {
app.use(morgan("tiny"));
}
connectToDb();
app.use("/api", router);
app.get("/", (req, res) => {
res.json("Hello world");
});
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerFile));
app.listen(4000, () => {
logger.info("Server is running on port 4000");
});