This commit is contained in:
@@ -1,4 +1,19 @@
|
||||
const API_BASE = 'http://127.0.0.1:8080/api';
|
||||
export const API_BASE = import.meta.env.VITE_API_BASE || 'http://127.0.0.1:8080/api';
|
||||
|
||||
export function getWsUrl(path: string): string {
|
||||
try {
|
||||
if (API_BASE.startsWith('http://') || API_BASE.startsWith('https://')) {
|
||||
const url = new URL(API_BASE);
|
||||
const protocol = url.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
return `${protocol}//${url.host}${path}`;
|
||||
}
|
||||
} catch (e) {
|
||||
// ignore
|
||||
}
|
||||
const protocol = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
return `${protocol}//${window.location.host}${path}`;
|
||||
}
|
||||
|
||||
|
||||
function getToken(): string | null {
|
||||
return localStorage.getItem('sc_staff_token');
|
||||
|
||||
Reference in New Issue
Block a user