- Removed API route that was conflicting with rewrite - Added explicit rewrite for /api/city/rooms -> /api/v1/city/rooms - Rewrite order matters: specific routes before wildcard
81 lines
2.6 KiB
TypeScript
81 lines
2.6 KiB
TypeScript
import type { NextConfig } from 'next'
|
|
|
|
const nextConfig: NextConfig = {
|
|
output: 'standalone',
|
|
|
|
async rewrites() {
|
|
// For Docker network: use service name
|
|
// INTERNAL_API_URL should be set to http://daarion-city-service:7001 in docker
|
|
// Fallback to localhost for local development
|
|
const internalApiUrl = process.env.INTERNAL_API_URL || 'http://daarion-city-service:7001'
|
|
|
|
console.log('[next.config] INTERNAL_API_URL:', internalApiUrl)
|
|
|
|
return {
|
|
// beforeFiles rewrites are checked before pages/public files
|
|
beforeFiles: [],
|
|
// afterFiles rewrites are checked after 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 (list) -> /api/v1/city/rooms
|
|
// Note: This must be before /api/city/:path* to take precedence
|
|
{
|
|
source: '/api/city/rooms',
|
|
destination: `${internalApiUrl}/api/v1/city/rooms`,
|
|
},
|
|
// 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 (excludes /api/city/rooms which is handled above)
|
|
{
|
|
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*`,
|
|
},
|
|
],
|
|
}
|
|
},
|
|
}
|
|
|
|
export default nextConfig
|
|
|