desktop 앱 적용
This commit is contained in:
@@ -6,13 +6,17 @@
|
||||
*/
|
||||
|
||||
import { storageGetSync, storageSetSync } from '../storage/index.js';
|
||||
import { getRuntimePlatform } from '../platform.js';
|
||||
|
||||
/** Flow layout stored with strategy (matches frontend StrategyFlowLayoutStore). */
|
||||
export type StrategyFlowLayoutStore = Record<string, unknown>;
|
||||
|
||||
/** 배포 APK·exdev 기본 (HTTPS 443 미개방 — 반드시 http) */
|
||||
/** 배포 APK·exdev (모바일 APK — http) */
|
||||
export const PRODUCTION_API_BASE = 'http://exdev.co.kr/api';
|
||||
|
||||
/** Tauri desktop — macOS ATS 호환 (https 필수) */
|
||||
export const DESKTOP_API_BASE = 'https://exdev.co.kr/api';
|
||||
|
||||
function viteEnv(): Record<string, string> | undefined {
|
||||
return typeof import.meta !== 'undefined'
|
||||
? (import.meta as ImportMeta & { env?: Record<string, string> }).env
|
||||
@@ -30,13 +34,29 @@ export function normalizeApiBaseUrl(url: string | null | undefined): string | nu
|
||||
return u;
|
||||
}
|
||||
|
||||
/** desktop 빌드 — vite define __DESKTOP_CLIENT__ (localhost API 사용 금지) */
|
||||
declare const __DESKTOP_CLIENT__: boolean | undefined;
|
||||
|
||||
function isDesktopClient(): boolean {
|
||||
if (typeof __DESKTOP_CLIENT__ !== 'undefined' && __DESKTOP_CLIENT__) return true;
|
||||
return typeof window !== 'undefined' && getRuntimePlatform() === 'desktop';
|
||||
}
|
||||
|
||||
function resolveApiBase(): string {
|
||||
// Desktop(Tauri): https exdev (macOS ATS — http 차단)
|
||||
if (isDesktopClient()) {
|
||||
return DESKTOP_API_BASE;
|
||||
}
|
||||
|
||||
const env = viteEnv();
|
||||
const fromStorage = normalizeApiBaseUrl(storageGetSync('gc_api_base_url'));
|
||||
const fromEnv = normalizeApiBaseUrl(env?.VITE_API_BASE_URL);
|
||||
if (fromStorage) return fromStorage;
|
||||
if (fromEnv) return fromEnv;
|
||||
if (env?.PROD) return PRODUCTION_API_BASE;
|
||||
const platform = typeof window !== 'undefined' ? getRuntimePlatform() : 'web';
|
||||
if (platform === 'mobile' || env?.PROD) {
|
||||
return PRODUCTION_API_BASE;
|
||||
}
|
||||
return 'http://localhost:8080/api';
|
||||
}
|
||||
|
||||
@@ -109,7 +129,7 @@ const DEFAULT_FETCH_TIMEOUT_MS = 45_000;
|
||||
const LOGIN_FETCH_TIMEOUT_MS = 180_000;
|
||||
|
||||
function wrapNetworkError(e: unknown): Error {
|
||||
if (e instanceof TypeError || (e instanceof Error && /failed to fetch/i.test(e.message))) {
|
||||
if (e instanceof TypeError || (e instanceof Error && /failed to fetch|load failed/i.test(e.message))) {
|
||||
return new Error(
|
||||
`서버에 연결할 수 없습니다 (${API_BASE}). Wi‑Fi·API 주소·앱 재설치 후 설정의 API URL을 확인하세요.`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user