fix: rename /api/internal/ to /api/node-internal/ to avoid routing issues
This commit is contained in:
57
apps/web/src/app/api/node-internal/[nodeId]/swapper/route.ts
Normal file
57
apps/web/src/app/api/node-internal/[nodeId]/swapper/route.ts
Normal 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 });
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ async function fetcher(url: string) {
|
|||||||
|
|
||||||
export function useNodeSwapper(nodeId: string) {
|
export function useNodeSwapper(nodeId: string) {
|
||||||
const { data, error, isLoading, mutate } = useSWR<NodeSwapperDetail>(
|
const { data, error, isLoading, mutate } = useSWR<NodeSwapperDetail>(
|
||||||
nodeId ? `/api/internal/node/${nodeId}/swapper` : null,
|
nodeId ? `/api/node-internal/${nodeId}/swapper` : null,
|
||||||
fetcher
|
fetcher
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user