import { NextResponse } from "next/server";

export async function GET() {
  const api =
    process.env.API_URL ||
    process.env.NEXT_PUBLIC_API_URL ||
    "";

  let probe: any = null;
  let probeError: any = null;

  try {
    const r = await fetch(`${api}/projects`, { cache: "no-store" });
    const text = await r.text();
    probe = {
      ok: r.ok,
      status: r.status,
      preview: text.slice(0, 200),
    };
  } catch (e: any) {
    probeError = String(e?.message || e);
  }

  return NextResponse.json({
    node_env: process.env.NODE_ENV,
    api_url: process.env.API_URL || null,
    next_public_api_url: process.env.NEXT_PUBLIC_API_URL || null,
    resolved_api_base: api,
    probe,
    probeError,
  });
}
