mirror of
https://github.com/Dvorinka/MyClubServer.git
synced 2026-06-04 02:32:57 +00:00
@@ -31,11 +31,15 @@ const resolveBackendUrl = (path: string) => {
|
||||
if (/^https?:\/\//i.test(path)) return path;
|
||||
if (path.startsWith('/cache') || path.startsWith('/uploads') || path.startsWith('/api/')) {
|
||||
const explicit = process.env.REACT_APP_API_BASE_URL || process.env.REACT_APP_API_URL || '';
|
||||
const origin = explicit
|
||||
? new URL(explicit, typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000').origin
|
||||
: (typeof window !== 'undefined' ? window.location.origin : 'http://localhost:3000');
|
||||
// Use URL constructor so query strings in `path` (e.g. /api/v1/x?t=123) are handled correctly
|
||||
return new URL(path, origin).toString();
|
||||
if (typeof window === 'undefined') {
|
||||
// In non-browser contexts, avoid forcing any origin; return the relative path
|
||||
return path;
|
||||
}
|
||||
const baseOrigin = explicit
|
||||
? new URL(explicit, window.location.origin).origin
|
||||
: window.location.origin;
|
||||
// Use URL constructor so query strings in `path` are handled correctly
|
||||
return new URL(path, baseOrigin).toString();
|
||||
}
|
||||
return path;
|
||||
} catch {
|
||||
|
||||
Reference in New Issue
Block a user