21 lines
426 B
TypeScript
21 lines
426 B
TypeScript
export function resolveDevProxyTarget(rawUrl: string | undefined) {
|
|
if (!rawUrl) {
|
|
return undefined;
|
|
}
|
|
|
|
try {
|
|
const url = new URL(rawUrl);
|
|
if (url.protocol === "ws:") {
|
|
url.protocol = "http:";
|
|
} else if (url.protocol === "wss:") {
|
|
url.protocol = "https:";
|
|
}
|
|
url.pathname = "";
|
|
url.search = "";
|
|
url.hash = "";
|
|
return url.toString();
|
|
} catch {
|
|
return undefined;
|
|
}
|
|
}
|