2021-09-25 09:29:05 +02:00
|
|
|
export default {
|
2023-04-26 11:39:32 +02:00
|
|
|
install(Vue, defaultServerFromLocation, onloaded) {
|
2021-09-25 09:29:05 +02:00
|
|
|
var config = Vue.observable(require('@/assets/config.json'));
|
2023-04-26 11:39:32 +02:00
|
|
|
const getRuntimeConfig = () => {
|
2023-10-13 09:31:45 +02:00
|
|
|
return fetch('./config.json?ms=' + Date.now()).then((res) => res.json()).catch(err => {
|
2023-04-26 11:39:32 +02:00
|
|
|
console.error("Failed to get config:", err);
|
|
|
|
|
return {};
|
|
|
|
|
});
|
2021-09-25 09:29:05 +02:00
|
|
|
}
|
|
|
|
|
|
2023-04-26 11:39:32 +02:00
|
|
|
config.promise = getRuntimeConfig().then((json) => {
|
2021-09-25 09:29:05 +02:00
|
|
|
// Reactively use all the config values
|
|
|
|
|
for (const key of Object.keys(json)) {
|
|
|
|
|
Vue.set(config, key, json[key]);
|
|
|
|
|
}
|
2021-12-14 09:53:09 +01:00
|
|
|
// If default server is not set, default to current server address
|
|
|
|
|
if (!json.defaultServer) {
|
2023-02-20 16:51:05 +01:00
|
|
|
Vue.set(config, "defaultServer", defaultServerFromLocation);
|
2021-12-14 09:53:09 +01:00
|
|
|
}
|
2023-04-26 11:39:32 +02:00
|
|
|
|
|
|
|
|
// Tell callback we are done loading runtime config
|
|
|
|
|
if (onloaded) {
|
|
|
|
|
onloaded(config);
|
|
|
|
|
}
|
|
|
|
|
return config;
|
2021-09-25 09:29:05 +02:00
|
|
|
});
|
|
|
|
|
Vue.prototype.$config = config;
|
|
|
|
|
}
|
|
|
|
|
}
|