11/**
2- * API configuration for score-backend
3- * Based on configuration from superscore/squirrel-local.cfg
2+ * API configuration for squirrel-backend
43 *
54 * In dev mode, Vite proxy forwards /v1/* to http://localhost:8080.
6- * In production (Tauri), VITE_API_URL is set at build time per facility.
5+ * In production (Tauri), config.json is read at startup to determine the backend URL.
6+ * Falls back to VITE_API_URL env var if config.json is not available.
77 */
88
9+ let runtimeBaseURL : string | null = null ;
10+
11+ /**
12+ * Load runtime configuration from config.json via Tauri FS API.
13+ * Must be called before the app renders. No-ops in non-Tauri environments.
14+ */
15+ export async function loadRuntimeConfig ( ) : Promise < void > {
16+ // eslint-disable-next-line @typescript-eslint/no-explicit-any, no-underscore-dangle
17+ if ( ! ( window as any ) . __TAURI__ ) return ;
18+
19+ try {
20+ const { resolveResource } = await import ( '@tauri-apps/api/path' ) ;
21+ const { readTextFile } = await import ( '@tauri-apps/api/fs' ) ;
22+
23+ const configPath = await resolveResource ( 'config.json' ) ;
24+ const text = await readTextFile ( configPath ) ;
25+ const config = JSON . parse ( text ) ;
26+ if ( config . apiUrl ) {
27+ runtimeBaseURL = config . apiUrl ;
28+ }
29+ } catch ( e ) {
30+ // eslint-disable-next-line no-console
31+ console . warn ( 'Could not load config.json, using build-time fallback' ) ;
32+ }
33+ }
34+
935export const API_CONFIG = {
10- baseURL : import . meta. env . VITE_API_URL || '' ,
36+ get baseURL ( ) : string {
37+ return runtimeBaseURL || import . meta. env . VITE_API_URL || '' ;
38+ } ,
1139 endpoints : {
1240 snapshots : '/v1/snapshots' ,
1341 pvs : '/v1/pvs' ,
@@ -18,7 +46,7 @@ export const API_CONFIG = {
1846} ;
1947
2048/**
21- * Generic API response wrapper from score -backend
49+ * Generic API response wrapper from squirrel -backend
2250 */
2351export interface ApiResultResponse < T > {
2452 errorCode : number ;
0 commit comments