From b9dd596652e47adc7e26fd9326f8e60b9419957d Mon Sep 17 00:00:00 2001 From: caadiq Date: Tue, 23 Dec 2025 16:29:10 +0900 Subject: [PATCH] =?UTF-8?q?feat:=20=EB=AA=A8=EB=93=9C=ED=8C=A9=20=EB=AA=A9?= =?UTF-8?q?=EB=A1=9D=20=EC=A1=B0=ED=9A=8C=20API=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - GET /api/modpacks: DB에서 모드팩 목록 조회 - contents_json을 파싱하여 contents 객체로 반환 - created_at DESC 정렬 --- backend/routes/api.js | 26 +++++++++++++++++++++++++- 1 file changed, 25 insertions(+), 1 deletion(-) 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;