2.3 KiB
2.3 KiB
F-131 — Reenviar query string en proxy catch-all del admin
Cambios
apps/admin/src/app/api/[...path]/route.ts
- 5 handlers (GET, POST, PATCH, PUT, DELETE) actualizados para incluir
req.nextUrl.searchal construir la URL hacia el backend. - Antes:
fetch(${API}/${path}, …)— descartaba cualquier query string. - Después:
fetch(${API}/${path}${search}, …)— reenvía?q=…&limit=…&offset=…al backend.
export async function GET(req: NextRequest) {
const path = req.nextUrl.pathname.replace('/api/', '');
+ const search = req.nextUrl.search;
…
- const backendRes = await fetch(`${API}/${path}`, { … });
+ const backendRes = await fetch(`${API}/${path}${search}`, { … });
(Mismo patrón aplicado a POST, PATCH, PUT, DELETE.)
Verificación
Antes del fix
GET /catalog/products?q=almendra&limit=5 (directo al backend)
→ 200 { total: 1, items: ['Almendras Crudas Ecologicas'] } ✅
GET /api/catalog/products?q=almendra&limit=5 (vía proxy del admin)
→ 200 { total: 13, items: [los 13 productos] } ❌ (q se pierde)
Después del fix
apps/admin/.next/server/chunks/[root-of-the-server]__0tr-qzw._.js.mapcontiene:fetch(`${API}/${path}${search}`, { headers: { Cookie: cookies } }) fetch(`${API}/${path}${search}`, { method: 'POST', … }) fetch(`${API}/${path}${search}`, { method: 'PATCH', … }) fetch(`${API}/${path}${search}`, { method: 'PUT', … }) fetch(`${API}/${path}${search}`, { method: 'DELETE', … })- Los 5 handlers ahora reenvían
search.
Tests
cd apps/admin && npx tsc --noEmit→ exit 0.cd apps/admin && NEXT_PUBLIC_API_URL=http://192.168.18.93:3000 npm run build→ exit 0.
Impacto colateral
Este fix también repara:
- F-126 (buscador /inventory): mismo síntoma, misma causa. Ahora
?q=…llega al backend. - Cualquier otro endpoint del admin que reciba query params (paginación
?limit=&offset=, filtros de fecha, etc.). - El frontend ya construye correctamente las URLs; el proxy era el cuello de botella.
Notas
- El operador debe reiniciar el admin (
./scripts/monolith.sh prod restart) para desplegar el bundle compilado. - Antes del restart, el bundle live en
:3004sigue con el bug (verificado:?q=almendraaún devuelve 13 productos a través del proxy).