feat: 添加query WS的功能
This commit is contained in:
24
src/utils.ts
Normal file
24
src/utils.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export const parseUrl = (url: string) => {
|
||||
try {
|
||||
new URL(url);
|
||||
} catch (e) {
|
||||
const _url = new URL(url, location.origin);
|
||||
return _url.href;
|
||||
}
|
||||
};
|
||||
|
||||
export const parseWsUrl = (url: string) => {
|
||||
try {
|
||||
new URL(url);
|
||||
return url;
|
||||
} catch (e) {
|
||||
const _url = new URL(url, location.origin);
|
||||
if (_url.protocol === 'http:') {
|
||||
_url.protocol = 'ws:';
|
||||
}
|
||||
if (_url.protocol === 'https:') {
|
||||
_url.protocol = 'wss:';
|
||||
}
|
||||
return _url.href;
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user