fix: remove duplicate API route, add dynamic export to swapper route
This commit is contained in:
@@ -1,57 +0,0 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
const CITY_SERVICE_URL =
|
||||
process.env.INTERNAL_API_URL ||
|
||||
process.env.CITY_SERVICE_URL ||
|
||||
'http://daarion-city-service:7001';
|
||||
|
||||
// Fallback response when swapper data is unavailable
|
||||
const fallbackResponse = (nodeId: string) => ({
|
||||
node_id: nodeId,
|
||||
healthy: false,
|
||||
models_loaded: 0,
|
||||
models_total: 0,
|
||||
models: [],
|
||||
});
|
||||
|
||||
export async function GET(
|
||||
_request: NextRequest,
|
||||
{ params }: { params: Promise<{ nodeId: string }> }
|
||||
) {
|
||||
const { nodeId } = await params;
|
||||
|
||||
if (!nodeId) {
|
||||
return NextResponse.json(
|
||||
{ error: 'nodeId is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
try {
|
||||
const url = `${CITY_SERVICE_URL}/city/internal/node/${encodeURIComponent(nodeId)}/swapper`;
|
||||
console.log('[swapper] Fetching:', url);
|
||||
|
||||
const upstream = await fetch(url, {
|
||||
cache: 'no-store',
|
||||
headers: {
|
||||
'content-type': 'application/json',
|
||||
},
|
||||
});
|
||||
|
||||
console.log('[swapper] Response status:', upstream.status);
|
||||
|
||||
if (!upstream.ok) {
|
||||
// Return fallback instead of error
|
||||
console.log('[swapper] Upstream not ok, returning fallback');
|
||||
return NextResponse.json(fallbackResponse(nodeId), { status: 200 });
|
||||
}
|
||||
|
||||
const payload = await upstream.json();
|
||||
return NextResponse.json(payload, { status: 200 });
|
||||
} catch (error) {
|
||||
// Return fallback instead of error
|
||||
console.error('[swapper] Error:', error);
|
||||
return NextResponse.json(fallbackResponse(nodeId), { status: 200 });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,7 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
export const dynamic = 'force-dynamic';
|
||||
|
||||
const CITY_SERVICE_URL =
|
||||
process.env.INTERNAL_API_URL ||
|
||||
process.env.CITY_SERVICE_URL ||
|
||||
|
||||
Reference in New Issue
Block a user