Skip to content

Commit

Permalink
coba
Browse files Browse the repository at this point in the history
  • Loading branch information
andifahruddinakas committed Oct 24, 2024
1 parent d5bc3ad commit f0133ab
Showing 1 changed file with 12 additions and 7 deletions.
19 changes: 12 additions & 7 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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`,
});
}

Expand All @@ -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));
Expand Down

0 comments on commit f0133ab

Please sign in to comment.