diff --git a/backend/routes/api.js b/backend/routes/api.js index f07d71f..df9f445 100644 --- a/backend/routes/api.js +++ b/backend/routes/api.js @@ -1,5 +1,5 @@ import express from "express"; -import { getTranslations, getIcons, getGamerules } from "../lib/db.js"; +import { getTranslations, getIcons, getGamerules, dbPool } from "../lib/db.js"; import { getIconUrl } from "../lib/icons.js"; import { MOD_API_URL, @@ -110,4 +110,28 @@ router.get("/worlds", async (req, res) => { } }); +// 모드팩 목록 조회 API +router.get("/modpacks", async (req, res) => { + try { + const [rows] = await dbPool.query(` + SELECT id, name, version, minecraft_version, mod_loader, changelog, + file_size, contents_json, created_at, updated_at + FROM modpacks + ORDER BY created_at DESC + `); + + // contents_json을 파싱하여 반환 + const modpacks = rows.map((row) => ({ + ...row, + contents: row.contents_json ? JSON.parse(row.contents_json) : null, + contents_json: undefined, // 원본 JSON 문자열은 제거 + })); + + res.json(modpacks); + } catch (error) { + console.error("[API] 모드팩 목록 조회 실패:", error.message); + res.status(500).json({ error: "서버 오류" }); + } +}); + export default router;