feat(node-dashboard): add MVP dashboard API endpoint
- services/city-service: add /api/v1/nodes/{id}/dashboard endpoint
- services/city-service: add legacy /api/v1/node/dashboard?nodeId=...
- apps/web: update route.ts to use city-service first
- apps/web: fallback to node-registry if city-service fails
Response structure:
node_id, name, kind, status, tags, agents_total,
agents_online, uptime (null), metrics_available (false)
Closes TASK_PHASE_NODE_DASHBOARD_API_MVP
This commit is contained in:
@@ -1,25 +1,39 @@
|
||||
import { NextRequest, NextResponse } from 'next/server';
|
||||
|
||||
const NODE_REGISTRY_URL = process.env.NODE_REGISTRY_URL || 'http://dagi-node-registry:9205';
|
||||
// Primary: city-service (has /api/v1/nodes/{id}/dashboard)
|
||||
// Fallback: node-registry (legacy, if configured)
|
||||
const CITY_SERVICE_URL = process.env.INTERNAL_API_URL || 'http://daarion-city-service:7001';
|
||||
const NODE_REGISTRY_URL = process.env.NODE_REGISTRY_URL || '';
|
||||
|
||||
export async function GET(request: NextRequest) {
|
||||
try {
|
||||
const { searchParams } = new URL(request.url);
|
||||
const nodeId = searchParams.get('nodeId');
|
||||
|
||||
// Build URL - either specific node or self
|
||||
const endpoint = nodeId
|
||||
? `${NODE_REGISTRY_URL}/api/v1/nodes/${nodeId}/dashboard`
|
||||
: `${NODE_REGISTRY_URL}/api/v1/nodes/self/dashboard`;
|
||||
if (!nodeId) {
|
||||
return NextResponse.json(
|
||||
{ error: 'nodeId query parameter is required' },
|
||||
{ status: 400 }
|
||||
);
|
||||
}
|
||||
|
||||
const response = await fetch(endpoint, {
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
},
|
||||
// Revalidate every 10 seconds
|
||||
// Try city-service first (MVP dashboard)
|
||||
const cityServiceEndpoint = `${CITY_SERVICE_URL}/api/v1/nodes/${nodeId}/dashboard`;
|
||||
|
||||
let response = await fetch(cityServiceEndpoint, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
next: { revalidate: 10 }
|
||||
});
|
||||
|
||||
// If city-service fails and node-registry is configured, try it as fallback
|
||||
if (!response.ok && NODE_REGISTRY_URL) {
|
||||
const nodeRegistryEndpoint = `${NODE_REGISTRY_URL}/api/v1/nodes/${nodeId}/dashboard`;
|
||||
response = await fetch(nodeRegistryEndpoint, {
|
||||
headers: { 'Content-Type': 'application/json' },
|
||||
next: { revalidate: 10 }
|
||||
});
|
||||
}
|
||||
|
||||
if (!response.ok) {
|
||||
return NextResponse.json(
|
||||
{ error: `Failed to fetch dashboard: ${response.status}` },
|
||||
@@ -38,4 +52,3 @@ export async function GET(request: NextRequest) {
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user