clean URL WebRTC for liveview
This commit is contained in:
+3
-2
@@ -30,15 +30,16 @@ export async function apiJson<T>(path: string, init?: RequestInit): Promise<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function normalizeLoopbackHost(rawUrl: string): string {
|
function normalizeLoopbackHost(rawUrl: string): string {
|
||||||
|
const cleaned = rawUrl.trim().replace(/^['"`\s]+|['"`\s]+$/g, "");
|
||||||
try {
|
try {
|
||||||
const url = new URL(rawUrl, window.location.origin);
|
const url = new URL(cleaned, window.location.origin);
|
||||||
const loopbacks = new Set(["127.0.0.1", "localhost", "::1"]);
|
const loopbacks = new Set(["127.0.0.1", "localhost", "::1"]);
|
||||||
if (loopbacks.has(url.hostname) && !loopbacks.has(window.location.hostname)) {
|
if (loopbacks.has(url.hostname) && !loopbacks.has(window.location.hostname)) {
|
||||||
url.hostname = window.location.hostname;
|
url.hostname = window.location.hostname;
|
||||||
}
|
}
|
||||||
return url.toString().replace(/\/+$/, "");
|
return url.toString().replace(/\/+$/, "");
|
||||||
} catch {
|
} catch {
|
||||||
return rawUrl.replace(/\/+$/, "");
|
return cleaned.replace(/\/+$/, "");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user