From f0133abebbb7052367838d84e262f1697c4cb6f4 Mon Sep 17 00:00:00 2001 From: Andi Fahruddin Akas Date: Thu, 24 Oct 2024 19:05:23 +0800 Subject: [PATCH] coba --- index.js | 19 ++++++++++++------- 1 file changed, 12 insertions(+), 7 deletions(-) diff --git a/index.js b/index.js index 3bf65fb85..c4a98c56e 100644 --- a/index.js +++ b/index.js @@ -19,24 +19,29 @@ app.get(["/api", "/api/desa"], (req, res) => { }); }); -app.get("/api/desa/:kodedesa/:tahun", (req, res) => { - const { kodedesa, tahun } = req.params; +app.get("/api/desa/:kodedesa", (req, res) => { + const { kodedesa } = req.params; const folderPath = path.join(__dirname, "public", "desa", kodedesa); - const filePath = path.join(folderPath, tahun + ".json"); - if (!tahun) { + if (!fs.existsSync(folderPath)) { return res.status(400).json({ status: 400, error: true, - message: "API endpoint not found", + message: `ID Desa tidak ditemukan`, }); } +}); + +app.get("/api/desa/:kodedesa/:tahun", (req, res) => { + const { kodedesa, tahun } = req.params; + const folderPath = path.join(__dirname, "public", "desa", kodedesa); + const filePath = path.join(folderPath, tahun + ".json"); if (!fs.existsSync(folderPath)) { return res.status(400).json({ status: 400, error: true, - message: `kodedesa ${kodedesa} tidak dikenali`, + message: `ID Desa tidak ditemukan`, }); } @@ -45,7 +50,7 @@ app.get("/api/desa/:kodedesa/:tahun", (req, res) => { return res.status(500).json({ status: 500, error: true, - message: "Error reading the file", + message: "ID Desa tidak ditemukan", }); } res.json(JSON.parse(data));