UNPKG

openclaw

Version:

Multi-channel AI gateway with extensible messaging integrations

48 lines (47 loc) • 1.65 kB
import { D as parseStrictPositiveInteger } from "./number-coercion-D6u-4YD8.mjs"; import { s as isLoopbackHost } from "./net-BgRayX-P.mjs"; //#region src/gateway/hosted-plugin-surface-url.ts const normalizeHost = (e, t) => { const n = e?.trim(); if (!n || t && isLoopbackHost(n)) return ""; return n; }; const parseHostHeader = (e) => { if (!e) return { host: "" }; const t = URL.parse(`http://${e.trim()}`); return t ? { host: t.hostname, port: parseStrictPositiveInteger(t.port) } : { host: "" }; }; const parseForwardedProto = (e) => { return Array.isArray(e) ? e[0] : e; }; const parseForwardedHost = (e) => { return (Array.isArray(e) ? e[0] : e)?.split(",")[0]?.trim(); }; /** Resolve the URL that plugins should advertise for hosted node surfaces. */ function resolveHostedPluginSurfaceUrl(e) { const t = e.port; if (!t) return; const n = parseForwardedProto(e.forwardedProto)?.trim() === "https" ? "https" : e.scheme ?? "http"; const r = normalizeHost(e.hostOverride, true); const i = parseForwardedHost(e.forwardedHost); const a = parseHostHeader(i); const o = parseHostHeader(e.requestHost); const s = normalizeHost(o.host, Boolean(r)); const c = normalizeHost(a.host, Boolean(r)); const l = c ? a : o; const u = normalizeHost(e.localAddress, Boolean(r || c || s)); const d = r || c || s || u; if (!d) return; let f = t; if (!r && (c || s)) { if (l.port && l.port > 0) f = l.port; else if (n === "https") f = 443; else if (n === "http") f = 80; } return `${n}://${d.includes(":") && !(d.startsWith("[") && d.endsWith("]")) ? `[${d}]` : d}:${f}`; } //#endregion export { resolveHostedPluginSurfaceUrl as t };