1- export const ALL_NAMESPACES = "all ";
1+ import { RuntimeConfig , defaultConfig , apiVersion } from "./config-defaults ";
22
3- interface RuntimeConfig {
4- url : string ;
5- }
6-
7- export const apiVersion = "v2" ;
8-
9- export const defaultConfig : RuntimeConfig = {
10- url :
11- apiVersion === "v2"
12- ? "http://localhost:31888/apis/ray.io/v1"
13- : "http://localhost:31888/apis/v1" ,
14- } ;
3+ export { defaultConfig , apiVersion } ;
4+ export type { RuntimeConfig } ;
155
166let runtimeConfig : RuntimeConfig | null = null ;
177
@@ -23,29 +13,50 @@ export async function fetchRuntimeConfig(): Promise<RuntimeConfig> {
2313 try {
2414 const response = await fetch ( "/api/config" ) ;
2515 if ( response . ok ) {
26- const data = await response . json ( ) ;
16+ const data : RuntimeConfig = await response . json ( ) ;
2717 runtimeConfig = {
28- url : data . apiUrl || defaultConfig . url ,
18+ domain : data . domain || defaultConfig . domain ,
19+ rayApiPath : data . rayApiPath || defaultConfig . rayApiPath ,
20+ coreApiPath :
21+ data . coreApiPath !== undefined
22+ ? data . coreApiPath
23+ : defaultConfig . coreApiPath ,
2924 } ;
3025 return runtimeConfig ;
3126 }
3227 } catch ( error ) {
3328 console . warn ( "Failed to fetch runtime config, using default:" , error ) ;
3429 }
3530
36- // Fallback to default config
3731 runtimeConfig = defaultConfig ;
3832 return runtimeConfig ;
3933}
4034
4135export const config = {
42- async getUrl ( ) : Promise < string > {
36+ async getRayApiUrl ( ) : Promise < string > {
4337 const cfg = await fetchRuntimeConfig ( ) ;
44- return cfg . url ;
38+ return ` ${ cfg . domain } ${ cfg . rayApiPath } ` ;
4539 } ,
4640
47- get url ( ) : string {
48- return runtimeConfig ?. url || defaultConfig . url ;
41+ async getCoreApiUrl ( ) : Promise < string | undefined > {
42+ const cfg = await fetchRuntimeConfig ( ) ;
43+ return cfg . coreApiPath ? `${ cfg . domain } ${ cfg . coreApiPath } ` : undefined ;
44+ } ,
45+
46+ get rayApiUrl ( ) : string {
47+ if ( runtimeConfig ) {
48+ return `${ runtimeConfig . domain } ${ runtimeConfig . rayApiPath } ` ;
49+ }
50+ return `${ defaultConfig . domain } ${ defaultConfig . rayApiPath } ` ;
51+ } ,
52+
53+ get coreApiUrl ( ) : string | undefined {
54+ if ( runtimeConfig ?. coreApiPath ) {
55+ return `${ runtimeConfig . domain } ${ runtimeConfig . coreApiPath } ` ;
56+ }
57+ return defaultConfig . coreApiPath
58+ ? `${ defaultConfig . domain } ${ defaultConfig . coreApiPath } `
59+ : undefined ;
4960 } ,
5061} ;
5162
0 commit comments