route.js 658 B

12345678910111213141516171819202122232425
  1. import { NextResponse } from "next/server";
  2. import { listBranches } from "@/lib/storage";
  3. /**
  4. * GET /api/branches
  5. *
  6. * Returns the list of branches (e.g. ["NL01", "NL02", ...]) based on the
  7. * directory names under NAS_ROOT_PATH.
  8. */
  9. export async function GET() {
  10. try {
  11. const branches = await listBranches();
  12. return NextResponse.json({ branches });
  13. } catch (error) {
  14. // Log the full error on the server for debugging
  15. console.error("[api/branches] Error reading branches:", error);
  16. // Return a generic error message to the client
  17. return NextResponse.json(
  18. { error: "Fehler beim Lesen der Niederlassungen" },
  19. { status: 500 }
  20. );
  21. }
  22. }