forked from junbyeol/kaist-ua-server
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
45 lines (40 loc) · 1.26 KB
/
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
41
42
43
44
45
require("dotenv").config();
const Koa = require("koa");
const bodyParser = require("koa-body");
const cors = require("@koa/cors");
const logger = require("koa-logger");
const router = require("./src/routes");
const models = require("./src/database/models/index.js");
const helmet = require("koa-helmet");
const swagger = require("koa2-swagger-ui");
const swaggerDoc = require("./src/utils/swaggerDef.js");
const { jwtMiddleware } = require("./src/utils");
const run = async () => {
const app = new Koa();
try {
await models.sequelize.authenticate();
console.log("Connection has been established successfully.");
} catch (error) {
console.error("Unable to connect to the database:", error);
}
app.use(cors({ credentials: true, origin: process.env.ORIGIN }));
app.use(helmet());
app.use(logger());
app.use(bodyParser());
app.use(jwtMiddleware);
app.use(router.routes()).use(router.allowedMethods());
app.use(
swagger({
routePrefix: "/swagger",
swaggerOptions: {
url: "/swagger.json",
},
})
);
app.use(swaggerDoc.routes());
const PORT = 8080;
app.listen(PORT, () => {
console.log(`Server running at port ${PORT}`);
});
};
run();