- digitaleInputsMockData.json angepasst: CGI-nahe Simulation mit CSV-Strings und Stringwerten - fetchDigitalInputsService.ts erweitert: - CSV-Zeilen werden automatisch in Arrays umgewandelt - Labels wie "'DE1','DE2'" werden korrekt aufgeteilt - Daten aus 4 CGI-Blöcken zu 32 Eingängen gemappt - ermöglicht realitätsnahe Tests in Entwicklungsumgebung ohne Produktion
31 lines
913 B
TypeScript
31 lines
913 B
TypeScript
// /pages/api/cpl/getDgitalInputsHandler.ts
|
|
import fs from "fs";
|
|
import path from "path";
|
|
import type { NextApiRequest, NextApiResponse } from "next";
|
|
|
|
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
|
try {
|
|
const mode = process.env.NEXT_PUBLIC_CPL_MODE;
|
|
|
|
if (mode === "json") {
|
|
const filePath = path.join(
|
|
process.cwd(),
|
|
"mocks",
|
|
"device-cgi-simulator",
|
|
"SERVICE",
|
|
"digitalInputsMockData.json"
|
|
);
|
|
const fileContent = fs.readFileSync(filePath, "utf-8");
|
|
const json = JSON.parse(fileContent);
|
|
return res.status(200).json(json);
|
|
}
|
|
|
|
return res.status(400).json({ error: "Ungültiger Modus" });
|
|
} catch (error) {
|
|
console.error("❌ Fehler beim Parsen der digitalen Eingänge:", error);
|
|
return res
|
|
.status(500)
|
|
.json({ error: "Fehler beim Parsen der digitalen Eingänge" });
|
|
}
|
|
}
|