- 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
42 lines
1.2 KiB
TypeScript
42 lines
1.2 KiB
TypeScript
// 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 (0–31) 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");
|
||
}
|
||
}
|