Adding external config support

This commit is contained in:
Bastien Wirtz 2020-06-09 19:11:42 -07:00
parent 52ed5af607
commit 1a42e30a17
2 changed files with 25 additions and 12 deletions

View File

@ -85,6 +85,10 @@ Title, icons, links, colors, and services can be configured in the `config.yml`
# Homepage configuration
# See https://fontawesome.com/icons for icons options
# Optional: Use external configuration file.
# Using this will ignore remaining config in this file
# externalConfig: https://example.com/server-luci/config.yaml
title: "App dashboard"
subtitle: "Homer"
logo: "assets/homer.png"

View File

@ -63,7 +63,7 @@
</h2>
<Service
v-for="item in group.items"
:key="item.url"
:key="item.name"
v-bind:item="item"
class="column is-one-third-widescreen"
/>
@ -153,19 +153,28 @@ export default {
document.title = `${this.config.title} | ${this.config.subtitle}`;
},
methods: {
getConfig: function () {
return fetch("config.yml")
.then((response) => {
getConfig: function (path = "config.yml") {
return fetch(path).then((response) => {
if (!response.ok) {
throw Error(response.statusText);
}
return response.text().then((body) => {
const that = this;
return response
.text()
.then((body) => {
return jsyaml.load(body);
});
})
.then(function (config) {
if (config.externalConfig) {
return that.getConfig(config.externalConfig);
}
return config;
})
.catch((error) => {
return this.handleErrors("⚠️ Error loading configuration", error);
});
});
},
matchesFilter: function (item) {
return (