import { NextRequest, NextResponse } from "next/server";

const EVENT_BUS_URL = process.env.EVENT_BUS_URL || "http://127.0.0.1:8089";

export async function GET(req: NextRequest) {
  try {
    const url = new URL(req.url);
    const params = url.searchParams.toString();
    const target = `${EVENT_BUS_URL}/events${params ? `?${params}` : ""}`;
    const res = await fetch(target);
    const data = await res.json();
    return NextResponse.json(data);
  } catch {
    return NextResponse.json(
      { error: "Event bus unavailable" },
      { status: 503 }
    );
  }
}
