-
Notifications
You must be signed in to change notification settings - Fork 1
/
app.js
76 lines (60 loc) · 1.9 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
const express = require("express");
const path = require("path");
const cookieParser = require("cookie-parser");
const logger = require("morgan");
const dotenv = require("dotenv");
const http = require("http");
const cors = require("cors");
dotenv.config();
const { stream } = require("./config/winston");
const { fail } = require("./util/resUtil");
const leaguesAPI = require("./router/leaguesAPI.router");
const auth = require("./router/auth");
const userSetting = require("./router/userSetting");
const infoRouter = require("./router/info.router");
const pogRouter = require("./router/pog.router");
const tinderRouter = require("./router/tinder.router");
const chatbot = require("./cron/chatbot");
const app = express();
if (process.env.NODE_ENV == "dev") {
app.use(logger("dev"));
} else if (process.env.NODE_ENV == "production") {
app.use(logger("combined", { stream }));
}
const { sequelize } = require("./models/index");
sequelize
.sync({ force: false })
.then(() => {})
.catch((err) => {
console.error(err);
});
app.set("views", path.join(__dirname, "public/views"));
app.set("view engine", "ejs");
app.use(express.json());
app.use(express.urlencoded({ extended: false }));
app.use(
cors({
exposedHeaders: "accesstoken, refreshtoken",
origin: true,
credentials: true,
})
);
app.use(express.static(path.join(__dirname, "public")));
app.use(cookieParser());
chatbot();
app.use("/leaguesApi", leaguesAPI);
app.use("/auth", auth);
app.use("/userSetting", userSetting);
app.use("/info", infoRouter);
app.use("/pog", pogRouter);
app.use("/tinder", tinderRouter);
app.use(function (req, res, next) {
res.status(404).send(fail(404, "요청한 API 주소가 존재하지 않습니다."));
});
const server = http.createServer(app);
if (process.env.NODE_ENV != "test") {
server.listen(process.env.PORT, () => {
console.log("Server listening PORT : " + process.env.PORT);
});
}
module.exports = { server };