import { normalizeServerOrigin } from "../../api-base.js";

export async function verifyServerConnection(value, fetchImpl = globalThis.fetch) {
  const origin = normalizeServerOrigin(value);
  try {
    const response = await fetchImpl(`${origin}/api/health`, { cache: "no-store", credentials: "include" });
    if (!response.ok) throw new Error("pc_unreachable");
    return origin;
  } catch {
    throw new Error("pc_unreachable");
  }
}
