-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathapp.js
87 lines (74 loc) ยท 2.58 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
79
80
81
82
83
84
85
86
87
const express = require("express");
const cors = require("cors");
const app = express();
const port = 8080; // port ๋ฒํธ ์ค์
const bodyParser = require("body-parser");
var createError = require("http-errors");
// router ์ค์
var apiRouter = require("./routes/api");
var adminRouter = require("./routes/api/admin");
var buildingRouter = require("./routes/api/buildings");
var magazineRouter = require("./routes/api/magazines");
var oauthRouter = require("./routes/api/oauth");
var popupRouter = require("./routes/api/popups");
var publicDataRouter = require("./routes/api/public_data");
var userRouter = require("./routes/api/users");
var contactRouter = require("./routes/api/contact");
// ์๋ฒ ์ ์ ๊ธฐ๋ณธ ์์ง ์ค์
const path = require("path");
app.set("view engine", "ejs");
app.set("views", path.join(__dirname, "views"));
// Swagger setting
const swaggerUi = require("swagger-ui-express");
const swaggerFile = require("./swagger_output.json");
// DB
var maria = require("./config/maria");
maria.connect();
var allowlist = [
"http://localhost:3000",
"https://localhost:3000",
"http://ec2-3-23-49-89.us-east-2.compute.amazonaws.com",
"http://ec2-3-34-222-145.ap-northeast-2.compute.amazonaws.com",
"https://neul-pum.vercel.app",
"https://neul-pum.vercel.app",
"https://www.gongganieum.com",
];
app.use((req, res, next) => {
console.log("\t");
console.log("====================== NEW REQ START =====================");
console.log("Received request:", req.method, req.url);
next();
});
app.use(
cors((req, callback) => {
const origin = req.header("Origin");
// console.log("CORS Origin Check:", origin);
const corsOptions = allowlist.includes(origin)
? { origin: true }
: { origin: false };
callback(null, corsOptions);
})
);
// Use Swagger
app.use("/swagger", swaggerUi.serve, swaggerUi.setup(swaggerFile));
//body-parser ๋ชจ๋์ ๋ถ๋ฌ์จ๋ค.
app.use(bodyParser.json()); //์์ฒญ ๋ณธ๋ฌธ์ json ํํ๋ก ํ์ฑ
app.use(bodyParser.urlencoded({ extended: false })); //
// endpoint root ์ฃผ์ ๋งคํ
app.use("/api/popup", popupRouter);
app.use("/api/building", buildingRouter);
app.use("/api/magazine", magazineRouter);
app.use("/api/user", userRouter);
app.use("/api/oauth", oauthRouter);
app.use("/api/data", publicDataRouter);
app.use("/api/admin", adminRouter);
app.use("/api/contact", contactRouter);
app.use("/api", apiRouter); // ๊ธฐํ api๋ค
// catch 404 and forward to error handler
app.use(function (req, res, next) {
next(createError(404));
});
app.listen(port, () => {
console.log(`listening on port ${port}`);
});
module.exports = app;