// /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(),
    "mocks",
    "device-cgi-simulator",
    "SERVICE",
    "kabelueberwachungMockData.js"
  );

  try {
    const data = await fs.readFile(filePath, "utf-8");
    res.setHeader("Content-Type", "application/javascript; charset=utf-8");
    // Prevent caching during development
    res.setHeader("Cache-Control", "no-store, max-age=0");
    res.status(200).send(data);
  } catch (error) {
    console.error(
      "Fehler bei der Verarbeitung von kabelueberwachungAPIHandler:",
      error
    );
    res.status(500).json({ error: "Interner Serverfehler" });
  }
}
