From 1a42e30a1752be5ab0fba5b224fad5686f12499e Mon Sep 17 00:00:00 2001 From: Bastien Wirtz Date: Tue, 9 Jun 2020 19:11:42 -0700 Subject: [PATCH] Adding external config support --- README.md | 4 ++++ src/App.vue | 33 +++++++++++++++++++++------------ 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index e9483f9..c3a6f07 100644 --- a/README.md +++ b/README.md @@ -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" diff --git a/src/App.vue b/src/App.vue index fddc585..440ffa0 100644 --- a/src/App.vue +++ b/src/App.vue @@ -63,7 +63,7 @@ @@ -153,19 +153,28 @@ export default { document.title = `${this.config.title} | ${this.config.subtitle}`; }, methods: { - getConfig: function () { - return fetch("config.yml") - .then((response) => { - if (!response.ok) { - throw Error(response.statusText); - } - return response.text().then((body) => { + getConfig: function (path = "config.yml") { + return fetch(path).then((response) => { + if (!response.ok) { + throw Error(response.statusText); + } + + 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); }); - }) - .catch((error) => { - return this.handleErrors("⚠️ Error loading configuration", error); - }); + }); }, matchesFilter: function (item) { return ( -- 2.41.0