route.js 687 B

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