fix: rename /api/internal/ to /api/node-internal/ to avoid routing issues

This commit is contained in:
Apple
2025-12-01 04:00:38 -08:00
parent b55c59b9d1
commit 2589f2d99d
2 changed files with 58 additions and 1 deletions

View File

@@ -0,0 +1,57 @@
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 });
}
}

View File

@@ -26,7 +26,7 @@ async function fetcher(url: string) {
export function useNodeSwapper(nodeId: string) {
const { data, error, isLoading, mutate } = useSWR<NodeSwapperDetail>(
nodeId ? `/api/internal/node/${nodeId}/swapper` : null,
nodeId ? `/api/node-internal/${nodeId}/swapper` : null,
fetcher
);