-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.js
78 lines (66 loc) · 1.88 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
"use strict";
require("module-alias/register");
const path = require("path");
const dotenv = require("dotenv");
dotenv.config({ path: path.join(__dirname, ".env") });
const express = require('express');
const bodyParser = require('body-parser');
const cors = require('cors');
const sequelize = require('./models').sequelize;
const responseHandler = require('@utils/responseHandler');
const routes = require('@routes');
/*============================
Swagger Definition
============================*/
const swaggerJSDoc = require("swagger-jsdoc");
const swaggerUI = require("swagger-ui-express");
const swaggerDefinition = {
info: {
title: "deepblock backend",
version: "1.0.0",
description: "deepblock backend api document",
},
};
const options = {
swaggerDefinition,
apis: [
"./routes/index.js",
"./routes/users/index.js",
"./routes/project/index.js",
"./routes/project/model/index.js",
"./routes/dataset/index.js",
"./routes/dataset/classes/index.js",
"./routes/dataset/classes/image/index.js",
],
};
const swaggerSpec = swaggerJSDoc(options);
/*============================
Init express server
============================*/
const app = express();
sequelize.sync();
app.use(bodyParser.json());
// set cors
app.use(
cors({
origin: true,
credentials: true,
})
);
/*==============================
Request API - route
==============================*/
app.use("/docs", swaggerUI.serve, swaggerUI.setup(swaggerSpec));
app.use("/api", routes);
/*============================
Error handling
============================*/
app.use(function (req, res, next) {
responseHandler.fail(res, 404, "404 Not found TT");
});
/*=============================
Listening
=============================*/
app.listen(process.env.SERVER_PORT || "8000", function (req, res) {
console.log(`listening on port ${process.env.SERVER_PORT}`);
});