33 lines
734 B
TypeScript
33 lines
734 B
TypeScript
// /pages/api/cpl/tdrDataAPIHandler.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(),
|
|
"mocks",
|
|
"device-cgi-simulator",
|
|
"TDR",
|
|
`${id}.json`
|
|
);
|
|
|
|
try {
|
|
const data = await fs.readFile(filePath, "utf-8");
|
|
res.status(200).json(JSON.parse(data));
|
|
} catch (error) {
|
|
console.error("Error processing tdrDataAPIHandler:", error);
|
|
res.status(404).json({ error: "File not found" });
|
|
}
|
|
}
|