31 lines
1.1 KiB
JavaScript
31 lines
1.1 KiB
JavaScript
export default {
|
|
install(Vue, defaultServerFromLocation, onloaded) {
|
|
var config = Vue.observable(require('@/assets/config.json'));
|
|
Vue.set(config, "loaded", false);
|
|
const getRuntimeConfig = () => {
|
|
return fetch('./config.json?ms=' + Date.now()).then((res) => res.json()).catch(err => {
|
|
console.error("Failed to get config:", err);
|
|
return {};
|
|
});
|
|
}
|
|
|
|
config.promise = getRuntimeConfig().then((json) => {
|
|
// Reactively use all the config values
|
|
for (const key of Object.keys(json)) {
|
|
Vue.set(config, key, json[key]);
|
|
}
|
|
// If default server is not set, default to current server address
|
|
if (!json.defaultServer) {
|
|
Vue.set(config, "defaultServer", defaultServerFromLocation);
|
|
}
|
|
Vue.set(config, "loaded", true);
|
|
|
|
// Tell callback we are done loading runtime config
|
|
if (onloaded) {
|
|
onloaded(config);
|
|
}
|
|
return config;
|
|
});
|
|
Vue.prototype.$config = config;
|
|
}
|
|
}
|