Files
CPLv4.0/pages/api/cpl/readKnotenpunktAPIHandler.ts
ISA 83ff40f27f feat: Integration von CGI-Interface für dynamische Knotenpunktdaten in Produktionsumgebung
- Knotenpunkte.tsx angepasst: <script>-basierte Einbindung von kueDataX.js über CGI-Endpoint (/CPL?/CPL/Service/kueDataKnoten/kueDataX.js)
- Verwendung von window.kueNodeID zur Anzeige der dynamisch geladenen Daten
- Files in Browser DevTools > Sources sichtbar dank echter Script-Einbindung
- Platzhalterlose kueDataX.js-Dateien erstellt und eingebunden
- Produktionsbuild erfolgreich getestet und in /out-Verzeichnis übertragen
2025-04-23 09:56:01 +02:00

42 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// pages/api/cpl/readKnotenpunktAPIHandler.ts
import fs from "fs";
import path from "path";
import { NextApiRequest, NextApiResponse } from "next";
/**
* API-Handler, um eine Knotenpunkt-Mockdatei für einen bestimmten Slot (031) als JavaScript zu laden.
* Diese Datei wird im Frontend als <script src="..."> eingebunden.
*/
export default function handler(req: NextApiRequest, res: NextApiResponse) {
const { slot } = req.query;
const slotIndex = Number(slot);
// Sicherheitsprüfung
if (isNaN(slotIndex) || slotIndex < 0 || slotIndex > 31) {
return res.status(400).send("// ❌ Ungültiger Slot-Index");
}
const filePath = path.resolve(
process.cwd(),
`apiMockData/SERVICE/knotenpunkte/slot${slotIndex}.js`
);
// Datei vorhanden?
if (!fs.existsSync(filePath)) {
return res
.status(404)
.send(`// ❌ Datei slot${slotIndex}.js nicht gefunden`);
}
try {
const fileContent = fs.readFileSync(filePath, "utf8");
res.setHeader("Content-Type", "application/javascript");
res.status(200).send(fileContent);
} catch (error) {
console.error("Fehler beim Lesen der Knotenpunkt-Datei:", error);
res.status(500).send("// ❌ Fehler beim Lesen der Datei");
}
}