fix: use afterFiles/fallback rewrites to allow Next.js API routes to work
This commit is contained in:
@@ -11,52 +11,60 @@ const nextConfig: NextConfig = {
|
|||||||
|
|
||||||
console.log('[next.config] INTERNAL_API_URL:', internalApiUrl)
|
console.log('[next.config] INTERNAL_API_URL:', internalApiUrl)
|
||||||
|
|
||||||
return [
|
return {
|
||||||
// Nodes API (public endpoints)
|
// beforeFiles rewrites are checked before pages/public files
|
||||||
{
|
// and after Next.js API routes - so API routes will work
|
||||||
source: '/api/nodes/list',
|
afterFiles: [
|
||||||
destination: `${internalApiUrl}/public/nodes`,
|
// Nodes API (public endpoints)
|
||||||
},
|
{
|
||||||
{
|
source: '/api/nodes/list',
|
||||||
source: '/api/nodes/:nodeId',
|
destination: `${internalApiUrl}/public/nodes`,
|
||||||
destination: `${internalApiUrl}/public/nodes/:nodeId`,
|
},
|
||||||
},
|
{
|
||||||
// Agent dashboard API -> /city/agents
|
source: '/api/nodes/:nodeId',
|
||||||
{
|
destination: `${internalApiUrl}/public/nodes/:nodeId`,
|
||||||
source: '/api/agents/:agentId/dashboard',
|
},
|
||||||
destination: `${internalApiUrl}/city/agents/:agentId/dashboard`,
|
// Agent dashboard API -> /city/agents
|
||||||
},
|
{
|
||||||
// Microdao API -> /city/microdao
|
source: '/api/agents/:agentId/dashboard',
|
||||||
{
|
destination: `${internalApiUrl}/city/agents/:agentId/dashboard`,
|
||||||
source: '/api/microdao/:path*',
|
},
|
||||||
destination: `${internalApiUrl}/city/microdao/:path*`,
|
// Microdao API -> /city/microdao
|
||||||
},
|
{
|
||||||
// Public API -> /public
|
source: '/api/microdao/:path*',
|
||||||
{
|
destination: `${internalApiUrl}/city/microdao/:path*`,
|
||||||
source: '/api/public/:path*',
|
},
|
||||||
destination: `${internalApiUrl}/public/:path*`,
|
// Public API -> /public
|
||||||
},
|
{
|
||||||
// City Rooms API (specific slug endpoint) -> /api/v1/city/rooms
|
source: '/api/public/:path*',
|
||||||
{
|
destination: `${internalApiUrl}/public/:path*`,
|
||||||
source: '/api/city/rooms/:slug',
|
},
|
||||||
destination: `${internalApiUrl}/api/v1/city/rooms/:slug`,
|
// City Rooms API (specific slug endpoint) -> /api/v1/city/rooms
|
||||||
},
|
{
|
||||||
// City API -> /city
|
source: '/api/city/rooms/:slug',
|
||||||
{
|
destination: `${internalApiUrl}/api/v1/city/rooms/:slug`,
|
||||||
source: '/api/city/:path*',
|
},
|
||||||
destination: `${internalApiUrl}/city/:path*`,
|
// City API -> /city
|
||||||
},
|
{
|
||||||
// Governance/Audit/Incidents -> /api/v1
|
source: '/api/city/:path*',
|
||||||
{
|
destination: `${internalApiUrl}/city/:path*`,
|
||||||
source: '/api/v1/:path*',
|
},
|
||||||
destination: `${internalApiUrl}/api/v1/:path*`,
|
// Governance/Audit/Incidents -> /api/v1
|
||||||
},
|
{
|
||||||
// Fallback for other /api routes
|
source: '/api/v1/:path*',
|
||||||
{
|
destination: `${internalApiUrl}/api/v1/:path*`,
|
||||||
source: '/api/:path*',
|
},
|
||||||
destination: `${internalApiUrl}/: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*`,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
16
apps/web/src/app/api/_debug/api-config/route.ts
Normal file
16
apps/web/src/app/api/_debug/api-config/route.ts
Normal file
@@ -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(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
Reference in New Issue
Block a user