Files
whyrating-engine-legacy/web/app/api/pipelines/[pipelineId]/widgets/[widgetId]/route.ts
2026-02-02 18:19:00 +00:00

36 lines
1.0 KiB
TypeScript

import { NextRequest, NextResponse } from 'next/server';
const API_BASE_URL = process.env.NEXT_PUBLIC_API_URL || 'http://localhost:8001';
export async function GET(
request: NextRequest,
{ params }: { params: Promise<{ pipelineId: string; widgetId: string }> }
) {
try {
const { pipelineId, widgetId } = await params;
const { searchParams } = new URL(request.url);
// Forward query params
const queryString = searchParams.toString();
const url = `${API_BASE_URL}/api/pipelines/${pipelineId}/widgets/${widgetId}${queryString ? `?${queryString}` : ''}`;
const response = await fetch(url);
if (!response.ok) {
return NextResponse.json(
{ error: 'Failed to fetch widget data' },
{ status: response.status }
);
}
const data = await response.json();
return NextResponse.json(data);
} catch (error) {
console.error('Widget API error:', error);
return NextResponse.json(
{ error: 'Failed to fetch widget data' },
{ status: 500 }
);
}
}