-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapp.js
More file actions
58 lines (49 loc) · 1.8 KB
/
app.js
File metadata and controls
58 lines (49 loc) · 1.8 KB
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
const express = require("express");
const dotenv = require("dotenv");
const bodyParser = require("body-parser");
const cors = require("cors");
const path = require("path");
const userRoutes = require("./routes/user.routes");
const homeRoutes = require("./routes/home.routes");
const restaurantRoutes = require("./routes/restaurant.routes");
const searchRoutes = require("./routes/search.routes");
const scrapRouter = require("./routes/scrap.routes");
const reviewRoutes = require("./routes/review.routes");
const swaggerUi = require("swagger-ui-express");
const swaggerDocs = require("./swagger");
dotenv.config();
const app = express();
// Swagger UI 설정
app.use("/api-docs", swaggerUi.serve, swaggerUi.setup(swaggerDocs));
console.log("Swagger UI available at http://localhost:1234/api-docs");
// CORS 설정
const corsOptions = {
origin: (origin, callback) => {
const allowedOrigins = ["http://localhost:5173", "http://localhost:1234", "http://43.202.172.0:1234"];
if (!origin || allowedOrigins.includes(origin)) {
callback(null, true);
} else {
console.error("Blocked by CORS: ", origin);
callback(new Error("Not allowed by CORS"));
}
},
methods: ["GET", "POST", "PUT", "DELETE"],
allowedHeaders: ["Content-Type", "Authorization"],
credentials: true,
};
app.use(cors(corsOptions));
// Body parser 설정
app.use(bodyParser.json());
// API 라우트
app.use("/api/user", userRoutes);
app.use("/api/home", homeRoutes);
app.use("/api/restaurant", restaurantRoutes);
app.use("/api/search", searchRoutes);
app.use("/api/scrap", scrapRouter);
app.use("/api/user/review", reviewRoutes);
// React 정적 파일 서빙
app.use(express.static(path.join(__dirname, "dist")));
app.get("*", (req, res) => {
res.sendFile(path.resolve(__dirname, "dist", "index.html"));
});
module.exports = app;