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
This commit is contained in:
41
pages/api/cpl/readKnotenpunktAPIHandler.ts
Normal file
41
pages/api/cpl/readKnotenpunktAPIHandler.ts
Normal file
@@ -0,0 +1,41 @@
|
||||
// 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");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user