MCPcopy Create free account
hub / github.com/EvoMap/evolver / resolveHubUrl

Function resolveHubUrl

src/config.js:87–119  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

85const PUBLIC_DEFAULT_HUB_URL = 'https://evomap.ai';
86
87function resolveHubUrl() {
88 // Trim each candidate and fall through on empty/whitespace-only values.
89 // A trailing space in a `.env` value (common with quoted entries like
90 // A2A_HUB_URL="https://evomap.ai ") otherwise survives into endpoint
91 // construction: `hubUrl.replace(/\/+$/, '')` strips trailing slashes but
92 // NOT whitespace, producing "https://evomap.ai /a2a/events/poll" which
93 // fails URL validation (#580 Bug 1). `||` alone would also pick a
94 // whitespace-only override as "truthy", so trim-then-fall-through here.
95 const pick = (v) => { const t = (v == null ? '' : String(v)).trim(); return t || null; };
96 const raw = pick(process.env.A2A_HUB_URL)
97 || pick(process.env.EVOMAP_HUB_URL)
98 || pick(process.env.EVOLVER_DEFAULT_HUB_URL)
99 || PUBLIC_DEFAULT_HUB_URL;
100
101 if (process.env.EVOMAP_HUB_ALLOW_INSECURE !== '1') {
102 let parsed;
103 try {
104 parsed = new URL(raw);
105 } catch {
106 throw new Error(
107 '[config] Hub URL is not a valid URL: ' + JSON.stringify(raw) + '. ' +
108 'Set EVOMAP_HUB_ALLOW_INSECURE=1 to bypass (local dev / mock hub only).'
109 );
110 }
111 if (parsed.protocol !== 'https:') {
112 throw new Error(
113 '[config] Hub URL must use https:// — got ' + JSON.stringify(raw) + '. ' +
114 'Set EVOMAP_HUB_ALLOW_INSECURE=1 to bypass (local dev / mock hub only).'
115 );
116 }
117 }
118 return raw;
119}
120
121// --- Solidify & Validation ---
122

Callers 3

mainFunction · 0.50
config.test.jsFile · 0.50

Calls 1

pickFunction · 0.70

Tested by

no test coverage detected