refactor: API-Dateien konsequent auf *APIHandler.ts umbenannt und MockData-Handling optimiert
- Einheitliches Naming für API-Routen: *APIHandler.ts - Mock-Daten aus /apiMockData/SERVICE/ werden über API bereitgestellt - API-Endpoints sofort erkennbar und verständlich - Projektstruktur deutlich klarer und wartungsfreundlicher
This commit is contained in:
26
pages/api/cpl/analogeEingaengeAPIHandler.ts
Normal file
26
pages/api/cpl/analogeEingaengeAPIHandler.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// /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(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"analogeEingaengeMockData.js"
|
||||
);
|
||||
|
||||
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" });
|
||||
}
|
||||
}
|
||||
@@ -1,19 +0,0 @@
|
||||
// /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" });
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,4 @@
|
||||
// /pages/api/cpl/kueData.ts
|
||||
// /pages/api/cpl/digitalOutputsAPIHandler.ts
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
@@ -12,7 +12,7 @@ export default async function handler(
|
||||
process.cwd(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"kueData.js"
|
||||
"digitaleAusgaengeMockData.js"
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -1,21 +0,0 @@
|
||||
// /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" });
|
||||
}
|
||||
}
|
||||
26
pages/api/cpl/digitaleEingaengeAPIHandler.ts
Normal file
26
pages/api/cpl/digitaleEingaengeAPIHandler.ts
Normal file
@@ -0,0 +1,26 @@
|
||||
// /pages/api/cpl/digitaleEingaengeAPIHandler.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",
|
||||
"digitaleEingaengeMockData.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/kabelueberwachungAPIHandler.ts
Normal file
24
pages/api/cpl/kabelueberwachungAPIHandler.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
// /pages/api/cpl/kabelueberwachungAPIHandler.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",
|
||||
"kabelueberwachungMockData.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,4 +1,4 @@
|
||||
// /pages/api/cpl/last20Messages.ts
|
||||
// /pages/api/cpl/last20MessagesAPIHandler.ts
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
@@ -11,7 +11,7 @@ export default async function handler(
|
||||
process.cwd(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"last20Messages.js"
|
||||
"last20MessagesMockData.js"
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -1,4 +1,4 @@
|
||||
// /pages/api/cpl/systemSettings.ts
|
||||
// /pages/api/cpl/opcuaSettingsAPIHandler.ts
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
@@ -12,7 +12,7 @@ export default async function handler(
|
||||
process.cwd(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"system.js"
|
||||
"opcuaMockData.js"
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -1,4 +1,4 @@
|
||||
// /pages/api/cpl/slotData.ts
|
||||
// /pages/api/cpl/slotDataAPIHandler.ts
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
import fs from "fs/promises";
|
||||
@@ -1,4 +1,4 @@
|
||||
// /pages/api/cpl/opcuaSettings.ts
|
||||
// /pages/api/cpl/systemSettingsAPIHandler.ts
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
@@ -12,7 +12,7 @@ export default async function handler(
|
||||
process.cwd(),
|
||||
"apiMockData",
|
||||
"SERVICE",
|
||||
"opcua.js"
|
||||
"systemMockData.js"
|
||||
);
|
||||
|
||||
try {
|
||||
@@ -1,4 +1,4 @@
|
||||
// /pages/api/cpl/tdmData.ts
|
||||
// /pages/api/cpl/tdmDataAPIHandler.ts
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
@@ -1,4 +1,4 @@
|
||||
// /pages/api/cpl/tdrData.ts
|
||||
// /pages/api/cpl/tdrDataAPIHandler.ts
|
||||
|
||||
import { NextApiRequest, NextApiResponse } from "next";
|
||||
import path from "path";
|
||||
Reference in New Issue
Block a user