import { NextResponse } from 'next/server';

export const dynamic = 'force-dynamic';

const BACKEND_URL = process.env.BACKEND_URL || 'http://localhost:3000';

/**
 * Ticker proxy (Session 45) — forwards GET /api/ticker to Express (snapshot
 * exhaust + editorial pins). Thin pass-through; the page polls this every 30s.
 */
export async function GET() {
  try {
    const upstream = await fetch(`${BACKEND_URL}/api/ticker`, {
      method: 'GET',
      headers: { Accept: 'application/json' },
    });
    const data = await upstream.json().catch(() => ({ items: [] }));
    return NextResponse.json(data, { status: upstream.ok ? 200 : upstream.status });
  } catch {
    return NextResponse.json({ items: [] }, { status: 200 });
  }
}
