From aa25a4158123314c4af020dee13799fe20e028ce Mon Sep 17 00:00:00 2001 From: makearmy Date: Mon, 22 Sep 2025 11:52:45 -0400 Subject: [PATCH] build bug fix --- app/api/options/[collection]/route.ts | 34 +++++++++++++-------------- 1 file changed, 16 insertions(+), 18 deletions(-) diff --git a/app/api/options/[collection]/route.ts b/app/api/options/[collection]/route.ts index 53446b4d..a153c1a2 100644 --- a/app/api/options/[collection]/route.ts +++ b/app/api/options/[collection]/route.ts @@ -2,8 +2,10 @@ import { NextResponse } from "next/server"; import { directusFetch } from "@/lib/directus"; -// Generic collections handled by this route. -// (laser_source has its own route so it's NOT included here) +/** + * Generic option lists resolved by collection name. + * NOTE: laser_source and lens have their own dedicated routes. + */ const MAP: Record< string, { path: string; fields: string; label: (x: any) => string } @@ -15,37 +17,33 @@ string, laser_software: { path: "/items/laser_software", fields: "id,name", label: (x) => x.name }, }; -export async function GET( - req: Request, - { params }: { params: { collection: string } } -) { +export async function GET(req: Request, ctx: any) { const { searchParams } = new URL(req.url); const q = searchParams.get("q")?.trim() || ""; const limit = Number(searchParams.get("limit") || "400"); - const key = params.collection; + + // Use a loose type for the 2nd arg to avoid Next 15's strict route signature check + const key = String(ctx?.params?.collection ?? ""); const cfg = MAP[key]; if (!cfg) { - // Unknown collection → empty list (prevents 4xx spam in logs) + // Unknown collection → return an empty list (avoids noisy 4xx) return NextResponse.json({ data: [] }); } - // Build query (use a dummy base so URL can append params cleanly) - const url = new URL("http://x" + cfg.path); - url.searchParams.set("fields", cfg.fields); - url.searchParams.set("limit", String(limit)); - if (q) url.searchParams.set("search", q); + // Build Directus URL (dummy base to use URL.searchParams ergonomically) + const u = new URL("http://x" + cfg.path); + u.searchParams.set("fields", cfg.fields); + u.searchParams.set("limit", String(limit)); + if (q) u.searchParams.set("search", q); try { const { data } = await directusFetch<{ data: any[] }>( - url.pathname + "?" + url.searchParams.toString() + u.pathname + "?" + u.searchParams.toString() ); const out = (data || []) - .map((it) => ({ - id: String(it.id), - label: cfg.label(it) ?? String(it.id), - })) + .map((it) => ({ id: String(it.id), label: cfg.label(it) ?? String(it.id) })) .sort((a, b) => a.label.localeCompare(b.label)); return NextResponse.json({ data: out });