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