@@ -19,13 +19,35 @@ Vue.use(FiltersPlugin)
1919// Load API configuration
2020// If we're in a local development environment,
2121// then we should load the env variables instead of the
22- // config.json
22+ // config.json. config.json can also be used to override
23+ // the default host for API and Websockets, if required.
2324const promise = new Promise < ApiConfig > ( ( resolve , reject ) => {
2425 if ( process . env . VUE_APP_API && process . env . VUE_APP_SOCKET ) {
26+ console . debug ( 'API Config from ENV' , process . env )
2527 resolve ( { apiUrl : process . env . VUE_APP_API , socketUrl : process . env . VUE_APP_SOCKET } )
2628 } else {
2729 fetch ( '/config.json' , { cache : 'no-store' } )
28- . then ( res => res . json ( ) )
30+ . then ( res => ( res . ok ) ? res . json ( ) : undefined )
31+ . then ( res => {
32+ if (
33+ res &&
34+ res . apiUrl &&
35+ res . socketUrl &&
36+ res . apiUrl !== '' &&
37+ res . socketUrl !== ''
38+ ) {
39+ console . debug ( 'API Config from JSON' , res )
40+ return res
41+ } else {
42+ const wsProtocol = document . location . protocol === 'https:' ? 'wss://' : 'ws://'
43+ const r = {
44+ apiUrl : '//' + window . location . host ,
45+ socketUrl : wsProtocol + window . location . host + '/websocket'
46+ }
47+ console . debug ( 'API Config from window.location' , r )
48+ return r
49+ }
50+ } )
2951 . then ( resolve )
3052 . catch ( reject )
3153 }
@@ -36,7 +58,7 @@ promise
3658 // Commit the api configuration to our store.
3759 store . commit ( 'config/onInitApiConfig' , apiConfig )
3860 return fetch ( apiConfig . apiUrl + '/server/files/config/' + Globals . SETTINGS_FILENAME , { cache : 'no-store' } )
39- . then ( res => ( ! res . ok ) ? undefined : res . json ( ) )
61+ . then ( res => ( res . ok ) ? res . json ( ) : undefined )
4062 . then ( ( fileConfig ) => {
4163 // Init the store. This should include any GUI settings we've loaded from moonraker.
4264 return store . dispatch ( 'init' , fileConfig ) . then ( ( ) => {
0 commit comments