fix: use afterFiles/fallback rewrites to allow Next.js API routes to work
This commit is contained in:
@@ -11,7 +11,10 @@ const nextConfig: NextConfig = {
|
||||
|
||||
console.log('[next.config] INTERNAL_API_URL:', internalApiUrl)
|
||||
|
||||
return [
|
||||
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',
|
||||
@@ -51,12 +54,17 @@ const nextConfig: NextConfig = {
|
||||
source: '/api/v1/:path*',
|
||||
destination: `${internalApiUrl}/api/v1/:path*`,
|
||||
},
|
||||
// Fallback for other /api routes
|
||||
],
|
||||
// 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