- API-Handler `updateDigitalOutputsHandler` überarbeitet:
- JSON-Dateien werden jetzt korrekt im gültigen Format gespeichert (`{ key: value }`)
- Schreibzugriff im production-Modus blockiert
- JS-Mock-Struktur vorbereitet (noch nicht aktiv getestet)
- Verzeichnisstruktur vereinheitlicht:
- JSON-Mocks unter `/mocks/api/SERVICE/`
- CGI-Platzhalter unter `/public/CPL/`
- JSMock-Ordner für CPL-Simulation vorbereitet (`/mocks/js-simulator/`)
- README.md um Betriebsmodi erweitert (`NEXT_PUBLIC_CPL_MODE` mit `json`, `jsmock`, `production`)
- `.env`-Dateien angepasst zur besseren Modussteuerung
28 lines
612 B
TypeScript
28 lines
612 B
TypeScript
// /pages/api/cpl/analogeEingaengeAPIHandler.ts
|
|
|
|
import { NextApiRequest, NextApiResponse } from "next";
|
|
import path from "path";
|
|
import fs from "fs/promises";
|
|
|
|
export default async function handler(
|
|
req: NextApiRequest,
|
|
res: NextApiResponse
|
|
) {
|
|
const filePath = path.join(
|
|
process.cwd(),
|
|
"mocks",
|
|
"api",
|
|
"SERVICE",
|
|
"digitaleAusgaengeMockData.json"
|
|
);
|
|
|
|
try {
|
|
const data = await fs.readFile(filePath, "utf-8");
|
|
|
|
res.setHeader("Content-Type", "text/javascript");
|
|
res.status(200).send(data);
|
|
} catch (error) {
|
|
res.status(404).json({ error: "File not found" });
|
|
}
|
|
}
|