import { g as getTelescopeSources } from './sources.server-C2PLxQXh.js';
import './shared-server-DaWdgxVh.js';
import 'zod';

const SOURCE_HEADER = "x-bosun-telescope-source";
const GET = async ({ params, url, request, fetch }) => {
  const path = params["path"] ?? "";
  let sources;
  try {
    sources = getTelescopeSources();
  } catch (error) {
    console.error("Failed to parse Telescope sources:", error);
    return new Response(
      JSON.stringify({ error: "Telescope sources are not configured correctly" }),
      {
        status: 500
      }
    );
  }
  if (!sources.length) {
    return new Response(JSON.stringify({ error: "No Telescope sources are configured" }), {
      status: 500
    });
  }
  const requestedSourceId = request.headers.get(SOURCE_HEADER) ?? "";
  const source = sources.find((s) => s.id === requestedSourceId) ?? sources[0];
  const targetUrl = `${source.baseUrl}/${path}${url.search}`;
  const resp = await fetch(targetUrl, { headers: { authorization: `Bearer ${source.apiKey}` } });
  return new Response(resp.body, { status: resp.status, headers: resp.headers });
};
const OPTIONS = async () => new Response(null, {
  status: 204,
  headers: {
    "Access-Control-Allow-Origin": "*",
    "Access-Control-Allow-Methods": "GET, POST, PUT, DELETE, OPTIONS",
    "Access-Control-Allow-Headers": "Content-Type, Authorization, x-bosun-telescope-source"
  }
});

export { GET, OPTIONS };
//# sourceMappingURL=_server.ts-B-GidZqI.js.map
