fix and update
This commit is contained in:
@@ -21,6 +21,10 @@ function usesSameOriginWsProxy(): boolean {
|
||||
return configuredWsUrl.includes('/idp-api/');
|
||||
}
|
||||
|
||||
function isLocalDevApiUrl(url: string): boolean {
|
||||
return /^https?:\/\/(localhost|127\.0\.0\.1)(:\d+)?(\/|$)/i.test(url);
|
||||
}
|
||||
|
||||
function resolveBrowserApiBaseUrl(): string {
|
||||
// SSR: внутренний URL Docker-сети (api-gateway), не публичный домен.
|
||||
if (typeof window === 'undefined') {
|
||||
@@ -31,12 +35,17 @@ function resolveBrowserApiBaseUrl(): string {
|
||||
return configuredApiUrl.replace(/\/+$/, '') || API_ORIGIN_PROXY_PREFIX;
|
||||
}
|
||||
|
||||
// Split-domain (https://api.example.com): браузер ходит напрямую на API-домен.
|
||||
// Same-origin (https://sso.example.com/idp-api): через /idp-api и host/nginx rewrites.
|
||||
if (usesSameOriginApiProxy()) {
|
||||
return API_ORIGIN_PROXY_PREFIX;
|
||||
}
|
||||
|
||||
// Split-domain (SSO на sso.*, API на api.*): браузер SPA ходит same-origin через
|
||||
// /idp-api на домене SSO. PUBLIC_API_URL=https://api.* остаётся для OAuth issuer и
|
||||
// внешних клиентов — cross-origin fetch из SPA не нужен и ломается (CORS/502).
|
||||
if (!isLocalDevApiUrl(configuredApiUrl)) {
|
||||
return API_ORIGIN_PROXY_PREFIX;
|
||||
}
|
||||
|
||||
return configuredApiUrl;
|
||||
}
|
||||
|
||||
@@ -50,6 +59,11 @@ function resolveBrowserWsBaseUrl(): string {
|
||||
return `${scheme}//${window.location.host}${API_ORIGIN_PROXY_PREFIX}/ws`;
|
||||
}
|
||||
|
||||
if (!/^wss?:\/\/(localhost|127\.0\.0\.1)/i.test(configuredWsUrl)) {
|
||||
const scheme = window.location.protocol === 'https:' ? 'wss:' : 'ws:';
|
||||
return `${scheme}//${window.location.host}${API_ORIGIN_PROXY_PREFIX}/ws`;
|
||||
}
|
||||
|
||||
return configuredWsUrl;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user