refactor: last20Messages und digitale Eingänge auf API-gesteuerte Mock-Dateien umgestellt
- Start.js (last20Messages) als JS-Mock in /apiMockData/jsMockFiles gespeichert - de.js (digitale Eingänge) in /apiMockData/SERVICE verlagert - Beide werden über eigene API-Endpoints bzw. per Script-Tag aus Development-Verzeichnis geladen - Kein Zugriff mehr über /public notwendig, Verhalten in DEV und PROD identisch
This commit is contained in:
19
pages/api/cpl/digitalOutputs.ts
Normal file
19
pages/api/cpl/digitalOutputs.ts
Normal file
@@ -0,0 +1,19 @@
|
||||
// /pages/api/cpl/digitalOutputs.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(), "apiMockData", "SERVICE", "da.js");
|
||||
|
||||
try {
|
||||
const data = await fs.readFile(filePath, "utf-8");
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
}
|
||||
21
pages/api/cpl/digitaleEingaenge.ts
Normal file
21
pages/api/cpl/digitaleEingaenge.ts
Normal file
@@ -0,0 +1,21 @@
|
||||
// /pages/api/cpl/digitaleEingaenge.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(), "apiMockData", "SERVICE", "de.js");
|
||||
|
||||
try {
|
||||
const data = await fs.readFile(filePath, "utf-8");
|
||||
|
||||
res.setHeader("Content-Type", "text/javascript"); // wichtig!
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
}
|
||||
24
pages/api/cpl/kueData.ts
Normal file
24
pages/api/cpl/kueData.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// /pages/api/cpl/kueData.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(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"kueData.js"
|
||||
);
|
||||
|
||||
try {
|
||||
const data = await fs.readFile(filePath, "utf-8");
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
}
|
||||
25
pages/api/cpl/last20Messages.ts
Normal file
25
pages/api/cpl/last20Messages.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// /pages/api/cpl/last20Messages.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(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"last20Messages.js"
|
||||
);
|
||||
|
||||
try {
|
||||
const data = await fs.readFile(filePath, "utf-8");
|
||||
|
||||
res.setHeader("Content-Type", "text/javascript"); // wichtig!
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
}
|
||||
24
pages/api/cpl/opcuaSettings.ts
Normal file
24
pages/api/cpl/opcuaSettings.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// /pages/api/cpl/opcuaSettings.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(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"opcua.js"
|
||||
);
|
||||
|
||||
try {
|
||||
const data = await fs.readFile(filePath, "utf-8");
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
}
|
||||
@@ -1,3 +1,4 @@
|
||||
// /pages/api/cpl/slotData.ts
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
|
||||
24
pages/api/cpl/systemSettings.ts
Normal file
24
pages/api/cpl/systemSettings.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// /pages/api/cpl/systemSettings.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(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"system.js"
|
||||
);
|
||||
|
||||
try {
|
||||
const data = await fs.readFile(filePath, "utf-8");
|
||||
res.status(200).send(data);
|
||||
} catch (error) {
|
||||
res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
}
|
||||
30
pages/api/cpl/tdmData.ts
Normal file
30
pages/api/cpl/tdmData.ts
Normal file
@@ -0,0 +1,30 @@
|
||||
// /pages/api/cpl/tdmData.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 { slot } = req.query;
|
||||
|
||||
if (!slot) {
|
||||
return res.status(400).json({ error: "Missing parameter: slot" });
|
||||
}
|
||||
|
||||
const filePath = path.join(
|
||||
process.cwd(),
|
||||
"apiMockData",
|
||||
"TDM",
|
||||
`slot${slot}.json`
|
||||
);
|
||||
|
||||
try {
|
||||
const data = await fs.readFile(filePath, "utf-8");
|
||||
res.status(200).json(JSON.parse(data));
|
||||
} catch (error) {
|
||||
res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
}
|
||||
25
pages/api/cpl/tdrData.ts
Normal file
25
pages/api/cpl/tdrData.ts
Normal file
@@ -0,0 +1,25 @@
|
||||
// /pages/api/cpl/tdrData.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 { id } = req.query;
|
||||
|
||||
if (!id) {
|
||||
return res.status(400).json({ error: "Missing parameter: id" });
|
||||
}
|
||||
|
||||
const filePath = path.join(process.cwd(), "apiMockData", "TDR", `${id}.json`);
|
||||
|
||||
try {
|
||||
const data = await fs.readFile(filePath, "utf-8");
|
||||
res.status(200).json(JSON.parse(data));
|
||||
} catch (error) {
|
||||
res.status(404).json({ error: "File not found" });
|
||||
}
|
||||
}
|
||||
@@ -1,11 +0,0 @@
|
||||
// pages/api/test.ts
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
|
||||
export default function handler(req: NextApiRequest, res: NextApiResponse) {
|
||||
res.status(200).json({
|
||||
message: "✅ Die API ist erreichbar!",
|
||||
method: req.method,
|
||||
timestamp: new Date().toISOString(),
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user