앱 실시간 차트 갱신오류 수정

This commit is contained in:
Macbook
2026-06-14 19:33:01 +09:00
parent 5045a548a4
commit c105ae209b
4 changed files with 52 additions and 11 deletions
+26 -1
View File
@@ -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;
}
+7
View File
@@ -3,6 +3,8 @@
* 훅·차트마다 WebSocket 을 열면 모바일에서 429·재연결 폭주가 발생한다.
*/
import type { UpbitMessage } from './upbitApi';
import { isDesktop } from './platform';
import { getSecureApiOrigin } from './backendApi';
export type UpbitWsChannel = 'ticker' | 'orderbook' | 'trade';
@@ -36,6 +38,11 @@ let closingIntentionally = false;
let wsFailureLogged = false;
function getWsUrl(): string {
if (isDesktop()) {
const origin = getSecureApiOrigin().replace(/^http:\/\//i, 'https://');
const host = origin.replace(/^https:\/\//i, '');
return `wss://${host}/upbit-ws`;
}
const proto = window.location.protocol === 'https:' ? 'wss' : 'ws';
return `${proto}://${window.location.host}/upbit-ws`;
}