Pull conf.yml from server

This commit is contained in:
aterox 2022-03-05 01:22:12 -05:00
parent df3e8e6f13
commit aeec449dc7
5 changed files with 32 additions and 3 deletions

View File

@ -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 */

10
services/get-conf.js Normal file
View File

@ -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;
};

View File

@ -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);

View File

@ -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 */

View File

@ -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',
},