import express from "express"; import path from "path"; import open from "open"; import fs from "fs"; const app = express(); app.use("/public", express.static(path.join(__dirname, "public"))); // app.use(express.urlencoded({ extends: true })); app.use(express.json()); app.listen(4000, () => { console.log("✅Pass: Server running at http://127.0.0.1:4000"); }); app.get("/", (req, res) => { res.sendFile(__dirname + "/public/index.html"); }); app.get("/api/meal", async (req, res) => { const item = req.query; const date = item.date; const type = item.type; const base_url = new URL("https://open.neis.go.kr/hub/mealServiceDietInfo"); const params = new URLSearchParams({ key: "6b442e68fabb4bee943947613b31eeee", Type: "json", ATPT_OFCDC_SC_CODE: "D10", SD_SCHUL_CODE: "7240450", MLSV_YMD: date, MMEAL_SC_CODE: type, }); const url = `${base_url}?${params.toString()}`; try { let data = await fetch(url); if (!data.ok) { res.send("No Information"); } data = await data.json(); if (!data.mealServiceDietInfo[1].row[0]) { res.send("No Information"); } let meal_list = data.mealServiceDietInfo[1].row[0].DDISH_NM; meal_list = meal_list.replace(/\([^)]+\)/g, "").split("
"); res.json({ meal_list: meal_list, kcal: data.mealServiceDietInfo[1].row[0].CAL_INFO, }); } catch (error) { res.send("No Information"); } });