2025-12-31 21:51:23 +09:00
|
|
|
import express from "express";
|
|
|
|
|
import path from "path";
|
|
|
|
|
import { fileURLToPath } from "url";
|
2026-01-01 00:26:04 +09:00
|
|
|
import membersRouter from "./routes/members.js";
|
2026-01-01 09:32:38 +09:00
|
|
|
import albumsRouter from "./routes/albums.js";
|
|
|
|
|
import statsRouter from "./routes/stats.js";
|
2026-01-01 18:01:42 +09:00
|
|
|
import adminRouter from "./routes/admin.js";
|
2026-01-05 22:16:02 +09:00
|
|
|
import schedulesRouter from "./routes/schedules.js";
|
2025-12-31 21:51:23 +09:00
|
|
|
|
|
|
|
|
const __filename = fileURLToPath(import.meta.url);
|
|
|
|
|
const __dirname = path.dirname(__filename);
|
|
|
|
|
|
|
|
|
|
const app = express();
|
|
|
|
|
const PORT = process.env.PORT || 80;
|
|
|
|
|
|
|
|
|
|
// JSON 파싱
|
|
|
|
|
app.use(express.json());
|
|
|
|
|
|
|
|
|
|
// 정적 파일 서빙 (프론트엔드 빌드 결과물)
|
|
|
|
|
app.use(express.static(path.join(__dirname, "dist")));
|
|
|
|
|
|
2026-01-01 00:26:04 +09:00
|
|
|
// API 라우트
|
2025-12-31 21:51:23 +09:00
|
|
|
app.get("/api/health", (req, res) => {
|
|
|
|
|
res.json({ status: "ok", timestamp: new Date().toISOString() });
|
|
|
|
|
});
|
|
|
|
|
|
2026-01-01 00:26:04 +09:00
|
|
|
app.use("/api/members", membersRouter);
|
2026-01-01 09:32:38 +09:00
|
|
|
app.use("/api/albums", albumsRouter);
|
|
|
|
|
app.use("/api/stats", statsRouter);
|
2026-01-01 18:01:42 +09:00
|
|
|
app.use("/api/admin", adminRouter);
|
2026-01-05 22:16:02 +09:00
|
|
|
app.use("/api/schedules", schedulesRouter);
|
|
|
|
|
app.use("/api/schedule-categories", (req, res, next) => {
|
|
|
|
|
// /api/schedule-categories -> /api/schedules/categories로 리다이렉트
|
|
|
|
|
req.url = "/categories";
|
|
|
|
|
schedulesRouter(req, res, next);
|
|
|
|
|
});
|
2026-01-01 00:26:04 +09:00
|
|
|
|
2025-12-31 21:51:23 +09:00
|
|
|
// SPA 폴백 - 모든 요청을 index.html로
|
|
|
|
|
app.get("*", (req, res) => {
|
|
|
|
|
res.sendFile(path.join(__dirname, "dist", "index.html"));
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
app.listen(PORT, () => {
|
|
|
|
|
console.log(`🌸 fromis_9 서버가 포트 ${PORT}에서 실행 중입니다`);
|
|
|
|
|
});
|