앱 실시간 차트 갱신오류 수정
This commit is contained in:
@@ -22,16 +22,41 @@ export function getApiBase(): string {
|
||||
return API_BASE.replace(/\/api$/, '');
|
||||
}
|
||||
|
||||
function isDesktopRuntime(): boolean {
|
||||
if (typeof window === 'undefined') return false;
|
||||
if ('__TAURI__' in window || '__TAURI_INTERNALS__' in window) return true;
|
||||
return document.documentElement.classList.contains('desktop-client');
|
||||
}
|
||||
|
||||
/** secure WebView(https) — ws:// mixed content 회피 */
|
||||
export function getSecureApiOrigin(): string {
|
||||
const origin = getApiBase().replace(/\/$/, '');
|
||||
const pageSecure =
|
||||
typeof window !== 'undefined'
|
||||
&& (window.location.protocol === 'https:' || isDesktopRuntime());
|
||||
if (pageSecure && /^http:\/\//i.test(origin)) {
|
||||
return origin.replace(/^http:/i, 'https:');
|
||||
}
|
||||
return origin;
|
||||
}
|
||||
|
||||
/**
|
||||
* STOMP SockJS 엔드포인트.
|
||||
* Spring Boot context-path가 /api 이므로 반드시 /api/ws/trading 경로를 사용한다.
|
||||
*/
|
||||
export function getStompSockJsUrl(): string {
|
||||
if (isDesktopRuntime()) {
|
||||
return `${getSecureApiOrigin()}/api/ws/trading`;
|
||||
}
|
||||
const base = API_BASE.replace(/\/$/, '');
|
||||
const path = base.endsWith('/api') ? `${base}/ws/trading` : `${base}/api/ws/trading`;
|
||||
// SockJS: 배포 환경에서 상대 경로만 쓰면 프록시/오리진 불일치 시 연결 실패가 난다.
|
||||
if (typeof window !== 'undefined' && window.location?.origin) {
|
||||
return `${window.location.origin}${path.startsWith('/') ? path : `/${path}`}`;
|
||||
const rel = path.startsWith('/') ? path : `/${path}`;
|
||||
if (window.location.protocol === 'https:' && /^http:\/\//i.test(path)) {
|
||||
return `${getSecureApiOrigin()}/api/ws/trading`;
|
||||
}
|
||||
return `${window.location.origin}${rel}`;
|
||||
}
|
||||
return path;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user