Spaces:
Build error
Build error
File size: 883 Bytes
b59aa07 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 |
/**
* Helper function to transform VS Code URLs
*
* This function checks if a VS Code URL points to localhost and replaces it with
* the current window's hostname if they don't match.
*
* @param vsCodeUrl The original VS Code URL from the backend
* @returns The transformed URL with the correct hostname
*/
export function transformVSCodeUrl(vsCodeUrl: string | null): string | null {
if (!vsCodeUrl) return null;
try {
const url = new URL(vsCodeUrl);
// Check if the URL points to localhost
if (
url.hostname === "localhost" &&
window.location.hostname !== "localhost"
) {
// Replace localhost with the current hostname
url.hostname = window.location.hostname;
return url.toString();
}
return vsCodeUrl;
} catch (error) {
// Silently handle the error and return the original URL
return vsCodeUrl;
}
}
|