diff --git a/apps/web/next.config.ts b/apps/web/next.config.ts index 7356df23..8b8c08eb 100644 --- a/apps/web/next.config.ts +++ b/apps/web/next.config.ts @@ -11,52 +11,60 @@ const nextConfig: NextConfig = { console.log('[next.config] INTERNAL_API_URL:', internalApiUrl) - return [ - // Nodes API (public endpoints) - { - source: '/api/nodes/list', - destination: `${internalApiUrl}/public/nodes`, - }, - { - source: '/api/nodes/:nodeId', - destination: `${internalApiUrl}/public/nodes/:nodeId`, - }, - // Agent dashboard API -> /city/agents - { - source: '/api/agents/:agentId/dashboard', - destination: `${internalApiUrl}/city/agents/:agentId/dashboard`, - }, - // Microdao API -> /city/microdao - { - source: '/api/microdao/:path*', - destination: `${internalApiUrl}/city/microdao/:path*`, - }, - // Public API -> /public - { - source: '/api/public/:path*', - destination: `${internalApiUrl}/public/:path*`, - }, - // City Rooms API (specific slug endpoint) -> /api/v1/city/rooms - { - source: '/api/city/rooms/:slug', - destination: `${internalApiUrl}/api/v1/city/rooms/:slug`, - }, - // City API -> /city - { - source: '/api/city/:path*', - destination: `${internalApiUrl}/city/:path*`, - }, - // Governance/Audit/Incidents -> /api/v1 - { - source: '/api/v1/:path*', - destination: `${internalApiUrl}/api/v1/:path*`, - }, - // Fallback for other /api routes - { - source: '/api/:path*', - destination: `${internalApiUrl}/:path*`, - }, - ] + return { + // beforeFiles rewrites are checked before pages/public files + // and after Next.js API routes - so API routes will work + afterFiles: [ + // Nodes API (public endpoints) + { + source: '/api/nodes/list', + destination: `${internalApiUrl}/public/nodes`, + }, + { + source: '/api/nodes/:nodeId', + destination: `${internalApiUrl}/public/nodes/:nodeId`, + }, + // Agent dashboard API -> /city/agents + { + source: '/api/agents/:agentId/dashboard', + destination: `${internalApiUrl}/city/agents/:agentId/dashboard`, + }, + // Microdao API -> /city/microdao + { + source: '/api/microdao/:path*', + destination: `${internalApiUrl}/city/microdao/:path*`, + }, + // Public API -> /public + { + source: '/api/public/:path*', + destination: `${internalApiUrl}/public/:path*`, + }, + // City Rooms API (specific slug endpoint) -> /api/v1/city/rooms + { + source: '/api/city/rooms/:slug', + destination: `${internalApiUrl}/api/v1/city/rooms/:slug`, + }, + // City API -> /city + { + source: '/api/city/:path*', + destination: `${internalApiUrl}/city/:path*`, + }, + // Governance/Audit/Incidents -> /api/v1 + { + source: '/api/v1/:path*', + destination: `${internalApiUrl}/api/v1/:path*`, + }, + ], + // fallback rewrites are checked after pages/public files + // and after dynamic routes, but before 404 + fallback: [ + // Fallback for other /api routes that don't have API route handlers + { + source: '/api/:path*', + destination: `${internalApiUrl}/:path*`, + }, + ], + } }, } diff --git a/apps/web/src/app/api/_debug/api-config/route.ts b/apps/web/src/app/api/_debug/api-config/route.ts new file mode 100644 index 00000000..49dc6d7b --- /dev/null +++ b/apps/web/src/app/api/_debug/api-config/route.ts @@ -0,0 +1,16 @@ +import { NextResponse } from 'next/server'; +import { getApiConfig } from '@/lib/apiProxy'; + +/** + * Debug endpoint to check API configuration + * GET /api/_debug/api-config + */ +export async function GET() { + const config = getApiConfig(); + + return NextResponse.json({ + ...config, + timestamp: new Date().toISOString(), + }); +} +