Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function createUrl(server: { [key: string]: string | number | undefined } | string): string {
if (typeof server === 'string') {
return normalizeUrl.default(server).replace(/^http/, 'ws');
}
const { host, hostname = location.hostname, port = location.port, path = '/', basePath = '' } = server;
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
const endHost = host || `${hostname}:${port}`;
return normalizeUrl.default(`${protocol}://${endHost}/${basePath}/${path}`);
}
export function createUrl(server: { [key: string]: string | number | undefined } | string): string {
if (typeof server === 'string') {
return normalizeUrl.default(server).replace(/^http/, 'ws');
}
const { host, hostname = location.hostname, port = location.port, path = '/', basePath = '' } = server;
const protocol = location.protocol === 'https:' ? 'wss' : 'ws';
const endHost = host || `${hostname}:${port}`;
return normalizeUrl.default(`${protocol}://${endHost}/${basePath}/${path}`);
}