-
Notifications
You must be signed in to change notification settings - Fork 1
/
server.ts
47 lines (39 loc) · 1.15 KB
/
server.ts
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
import dotenv from "dotenv";
dotenv.config();
import express from "express";
import bodyParser from "body-parser";
const port = process.env.PORT || 3000;
import router from "./routes/routes.js";
import { dbWS } from "./database/connection.js";
/*
** Managed by APIGateway **
import basicAuth from "express-basic-auth";
const basicAuthMiddleware = basicAuth({
challenge: true,
users: { [process.env.BASIC_AUTH_USERNAME]: process.env.BASIC_AUTH_PASSWORD },
});
*/
import { options } from "./swagger/config.js";
import swaggerJSDoc from "swagger-jsdoc";
const swaggerSpec = swaggerJSDoc(options);
import swaggerUi from "swagger-ui-express";
const app = express();
app.use(bodyParser.json());
app.use(
"/docs",
//basicAuthMiddleware,
swaggerUi.serve,
swaggerUi.setup(swaggerSpec)
);
app.use("/api/v1/", router);
dbWS
.authenticate()
.then(async () => {
app.listen(port, async function () {
console.log(`[WEBSERVER]: Server is listening on port ${port}!`);
console.log(`[WEBSERVER]: Database ${dbWS.getDatabaseName()} connected!`);
});
})
.catch((err) => {
console.error("[WEBSERVER]: Unable to connect to the database:", err);
});