import { aQ as useRuntimeConfig, aO as getRequestHeader } from '../nitro/nitro.mjs';

function getServerBaseUrl(event) {
  var _a, _b, _c, _d;
  const fromEnv = (_a = process.env.NOTTY_PUBLIC_URL) != null ? _a : process.env.PUBLIC_URL;
  if (fromEnv) {
    return fromEnv.replace(/\/+$/, "");
  }
  try {
    const runtime = useRuntimeConfig();
    const apiBase = (_b = runtime == null ? void 0 : runtime.public) == null ? void 0 : _b.apiBase;
    if (apiBase) {
      return apiBase.replace(/\/+$/, "");
    }
  } catch {
  }
  const host = (_c = getRequestHeader(event, "x-forwarded-host")) != null ? _c : getRequestHeader(event, "host");
  const proto = (_d = getRequestHeader(event, "x-forwarded-proto")) != null ? _d : host && host.startsWith("localhost") ? "http" : "https";
  if (host) {
    return `${proto}://${host}`;
  }
  return "http://localhost:2102";
}
function buildSsoCallbackUrl(event, slug) {
  return `${getServerBaseUrl(event)}/api/admin/auth/sso/${slug}/callback`;
}
function normalizeRedirectAfter(value) {
  if (typeof value !== "string" || value.length === 0) {
    return null;
  }
  if (value.length > 2e3) {
    return null;
  }
  if (!value.startsWith("/")) {
    return null;
  }
  if (value.startsWith("//")) {
    return null;
  }
  if (value.includes("\\")) {
    return null;
  }
  return value;
}

export { buildSsoCallbackUrl as b, getServerBaseUrl as g, normalizeRedirectAfter as n };
//# sourceMappingURL=url-helpers.mjs.map
