From aeec449dc7632fbeed381aa9429829d45be49eef Mon Sep 17 00:00:00 2001 From: aterox Date: Sat, 5 Mar 2022 01:22:12 -0500 Subject: [PATCH 01/11] Pull conf.yml from server --- server.js | 9 +++++++++ services/get-conf.js | 10 ++++++++++ src/store.js | 11 ++++++++++- src/utils/ConfigAccumalator.js | 4 ++-- src/utils/defaults.js | 1 + 5 files changed, 32 insertions(+), 3 deletions(-) create mode 100644 services/get-conf.js diff --git a/server.js b/server.js index 4cef9e23..7d395ade 100644 --- a/server.js +++ b/server.js @@ -27,6 +27,7 @@ const rebuild = require('./services/rebuild-app'); // A script to programmatical const systemInfo = require('./services/system-info'); // Basic system info, for resource widget const sslServer = require('./services/ssl-server'); // TLS-enabled web server const corsProxy = require('./services/cors-proxy'); // Enables API requests to CORS-blocked services +const getConf = require('./services/get-conf'); // Returns the configuration as a JSON object /* Helper functions, and default config */ const printMessage = require('./services/print-message'); // Function to print welcome msg on start @@ -116,6 +117,14 @@ const app = express() } catch (e) { res.end(JSON.stringify({ success: false, message: e })); } + }) + // GET endpoint returns the app configuration + .use(ENDPOINTS.getConf, (req, res) => { + try { + res.end(JSON.stringify(getConf())); + } catch (e) { + res.end(JSON.stringify({ success: false, message: e })); + } }); /* Create HTTP server from app on port, and print welcome message */ diff --git a/services/get-conf.js b/services/get-conf.js new file mode 100644 index 00000000..df952256 --- /dev/null +++ b/services/get-conf.js @@ -0,0 +1,10 @@ +/** + * Gets the configuration from conf.yml + */ +const fs = require('fs'); +const yaml = require('js-yaml'); + +module.exports = () => { + const conf = yaml.load(fs.readFileSync('./public/conf.yml', 'utf-8')); + return conf; +}; diff --git a/src/store.js b/src/store.js index 95ae846c..83bf628b 100644 --- a/src/store.js +++ b/src/store.js @@ -1,6 +1,7 @@ /* eslint-disable no-param-reassign, prefer-destructuring */ import Vue from 'vue'; import Vuex from 'vuex'; +import axios from 'axios'; import Keys from '@/utils/StoreMutations'; import ConfigAccumulator from '@/utils/ConfigAccumalator'; import { componentVisibility } from '@/utils/ConfigHelpers'; @@ -8,12 +9,14 @@ import { applyItemId } from '@/utils/SectionHelpers'; import filterUserSections from '@/utils/CheckSectionVisibility'; import { InfoHandler, InfoKeys } from '@/utils/ErrorHandler'; import { isUserAdmin } from '@/utils/Auth'; +import { serviceEndpoints } from '@/utils/defaults'; Vue.use(Vuex); const { INITIALIZE_CONFIG, SET_CONFIG, + SET_REMOTE_CONFIG, SET_MODAL_OPEN, SET_LANGUAGE, SET_ITEM_LAYOUT, @@ -38,6 +41,7 @@ const { const store = new Vuex.Store({ state: { config: {}, + remoteConfig: {}, // The configuration stored on the server editMode: false, // While true, the user can drag and edit items + sections modalOpen: false, // KB shortcut functionality will be disabled when modal is open navigateConfToTab: undefined, // Used to switch active tab in config modal @@ -126,6 +130,9 @@ const store = new Vuex.Store({ [SET_CONFIG](state, config) { state.config = config; }, + [SET_REMOTE_CONFIG](state, config) { + state.remoteConfig = config; + }, [SET_LANGUAGE](state, lang) { const newConfig = state.config; newConfig.appConfig.language = lang; @@ -271,7 +278,9 @@ const store = new Vuex.Store({ }, actions: { /* Called when app first loaded. Reads config and sets state */ - [INITIALIZE_CONFIG]({ commit }) { + async [INITIALIZE_CONFIG]({ commit }) { + // Get the config file from the server and store it for use by the accumulator + commit(SET_REMOTE_CONFIG, (await axios.get(serviceEndpoints.getConf)).data); const deepCopy = (json) => JSON.parse(JSON.stringify(json)); const config = deepCopy(new ConfigAccumulator().config()); commit(SET_CONFIG, config); diff --git a/src/utils/ConfigAccumalator.js b/src/utils/ConfigAccumalator.js index a1756461..15131e7d 100644 --- a/src/utils/ConfigAccumalator.js +++ b/src/utils/ConfigAccumalator.js @@ -14,11 +14,11 @@ import { } from '@/utils/defaults'; import ErrorHandler from '@/utils/ErrorHandler'; import { applyItemId } from '@/utils/SectionHelpers'; -import conf from '../../public/conf.yml'; +import $store from '../store'; export default class ConfigAccumulator { constructor() { - this.conf = conf; + this.conf = $store.state.remoteConfig; } /* App Config */ diff --git a/src/utils/defaults.js b/src/utils/defaults.js index 57cabb6d..aba08691 100644 --- a/src/utils/defaults.js +++ b/src/utils/defaults.js @@ -42,6 +42,7 @@ module.exports = { statusCheck: '/status-check', save: '/config-manager/save', rebuild: '/config-manager/rebuild', + getConf: '/config-manager/get', systemInfo: '/system-info', corsProxy: '/cors-proxy', }, From 7c86d6085bbd634970d0a7a3871458438adeefa6 Mon Sep 17 00:00:00 2001 From: aterox Date: Sat, 5 Mar 2022 01:22:32 -0500 Subject: [PATCH 02/11] Load components after config has been pulled --- src/App.vue | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/App.vue b/src/App.vue index d669556f..27984144 100644 --- a/src/App.vue +++ b/src/App.vue @@ -3,8 +3,8 @@
- -