Files
CPLv4.0/pages/api/cpl/getSystemspannung15VplusHandler.ts
2025-07-03 11:48:52 +02:00

34 lines
901 B
TypeScript

import { NextApiRequest, NextApiResponse } from "next";
import path from "path";
import fs from "fs/promises";
export default async function handler(
req: NextApiRequest,
res: NextApiResponse
) {
const { typ = "DIA0" } = req.query;
if (!["DIA0", "DIA1", "DIA2"].includes(typ as string)) {
return res
.status(400)
.json({ error: "Ungültiger Typ. Nur DIA0, DIA1 oder DIA2 erlaubt." });
}
try {
const filePath = path.join(
process.cwd(),
"mocks/device-cgi-simulator/chartsData/systemspannung15Vplus",
`${typ}.json`
);
const fileContent = await fs.readFile(filePath, "utf-8");
const json = JSON.parse(fileContent);
return res.status(200).json(json);
} catch (error) {
console.error("❌ Fehler beim Lesen der Datei:", error);
return res
.status(500)
.json({ error: "Datei konnte nicht gelesen werden." });
}
}