MCPcopy
hub / github.com/codedogQBY/ReadAny / ensureUrlProtocol

Function ensureUrlProtocol

packages/core/src/utils/api.ts:247–256  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

245 * "endpoint did not return JSON" error chain on connect.
246 */
247export function ensureUrlProtocol(url: string): string {
248 const trimmed = url.trim();
249 if (!trimmed) return trimmed;
250 if (/^[a-z][a-z0-9+\-.]*:\/\//i.test(trimmed)) return trimmed;
251 if (trimmed.startsWith("//")) return trimmed;
252 const stripped = trimmed.replace(/^\/+/, "");
253 const isLoopback =
254 /^(localhost(?:[:/]|$)|127\.\d+\.\d+\.\d+|0\.0\.0\.0(?:[:/]|$)|\[::1?\])/i.test(stripped);
255 return `${isLoopback ? "http://" : "https://"}${stripped}`;
256}
257
258function sanitizeOpenAICompatibleBaseUrl(url: string): string {
259 const trimmed = trimApiUrl(url);

Callers 4

api.test.tsFile · 0.90
formatApiHostFunction · 0.85
resolveProviderBaseUrlFunction · 0.85
buildProviderModelsUrlFunction · 0.85

Calls 1

replaceMethod · 0.80

Tested by

no test coverage detected