mirror of
https://github.com/Lissy93/dashy.git
synced 2025-07-08 22:34:54 +02:00
Pull conf.yml from server
This commit is contained in:
parent
df3e8e6f13
commit
aeec449dc7
@ -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 systemInfo = require('./services/system-info'); // Basic system info, for resource widget
|
||||||
const sslServer = require('./services/ssl-server'); // TLS-enabled web server
|
const sslServer = require('./services/ssl-server'); // TLS-enabled web server
|
||||||
const corsProxy = require('./services/cors-proxy'); // Enables API requests to CORS-blocked services
|
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 */
|
/* Helper functions, and default config */
|
||||||
const printMessage = require('./services/print-message'); // Function to print welcome msg on start
|
const printMessage = require('./services/print-message'); // Function to print welcome msg on start
|
||||||
@ -116,6 +117,14 @@ const app = express()
|
|||||||
} catch (e) {
|
} catch (e) {
|
||||||
res.end(JSON.stringify({ success: false, message: 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 */
|
/* Create HTTP server from app on port, and print welcome message */
|
||||||
|
10
services/get-conf.js
Normal file
10
services/get-conf.js
Normal 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;
|
||||||
|
};
|
11
src/store.js
11
src/store.js
@ -1,6 +1,7 @@
|
|||||||
/* eslint-disable no-param-reassign, prefer-destructuring */
|
/* eslint-disable no-param-reassign, prefer-destructuring */
|
||||||
import Vue from 'vue';
|
import Vue from 'vue';
|
||||||
import Vuex from 'vuex';
|
import Vuex from 'vuex';
|
||||||
|
import axios from 'axios';
|
||||||
import Keys from '@/utils/StoreMutations';
|
import Keys from '@/utils/StoreMutations';
|
||||||
import ConfigAccumulator from '@/utils/ConfigAccumalator';
|
import ConfigAccumulator from '@/utils/ConfigAccumalator';
|
||||||
import { componentVisibility } from '@/utils/ConfigHelpers';
|
import { componentVisibility } from '@/utils/ConfigHelpers';
|
||||||
@ -8,12 +9,14 @@ import { applyItemId } from '@/utils/SectionHelpers';
|
|||||||
import filterUserSections from '@/utils/CheckSectionVisibility';
|
import filterUserSections from '@/utils/CheckSectionVisibility';
|
||||||
import { InfoHandler, InfoKeys } from '@/utils/ErrorHandler';
|
import { InfoHandler, InfoKeys } from '@/utils/ErrorHandler';
|
||||||
import { isUserAdmin } from '@/utils/Auth';
|
import { isUserAdmin } from '@/utils/Auth';
|
||||||
|
import { serviceEndpoints } from '@/utils/defaults';
|
||||||
|
|
||||||
Vue.use(Vuex);
|
Vue.use(Vuex);
|
||||||
|
|
||||||
const {
|
const {
|
||||||
INITIALIZE_CONFIG,
|
INITIALIZE_CONFIG,
|
||||||
SET_CONFIG,
|
SET_CONFIG,
|
||||||
|
SET_REMOTE_CONFIG,
|
||||||
SET_MODAL_OPEN,
|
SET_MODAL_OPEN,
|
||||||
SET_LANGUAGE,
|
SET_LANGUAGE,
|
||||||
SET_ITEM_LAYOUT,
|
SET_ITEM_LAYOUT,
|
||||||
@ -38,6 +41,7 @@ const {
|
|||||||
const store = new Vuex.Store({
|
const store = new Vuex.Store({
|
||||||
state: {
|
state: {
|
||||||
config: {},
|
config: {},
|
||||||
|
remoteConfig: {}, // The configuration stored on the server
|
||||||
editMode: false, // While true, the user can drag and edit items + sections
|
editMode: false, // While true, the user can drag and edit items + sections
|
||||||
modalOpen: false, // KB shortcut functionality will be disabled when modal is open
|
modalOpen: false, // KB shortcut functionality will be disabled when modal is open
|
||||||
navigateConfToTab: undefined, // Used to switch active tab in config modal
|
navigateConfToTab: undefined, // Used to switch active tab in config modal
|
||||||
@ -126,6 +130,9 @@ const store = new Vuex.Store({
|
|||||||
[SET_CONFIG](state, config) {
|
[SET_CONFIG](state, config) {
|
||||||
state.config = config;
|
state.config = config;
|
||||||
},
|
},
|
||||||
|
[SET_REMOTE_CONFIG](state, config) {
|
||||||
|
state.remoteConfig = config;
|
||||||
|
},
|
||||||
[SET_LANGUAGE](state, lang) {
|
[SET_LANGUAGE](state, lang) {
|
||||||
const newConfig = state.config;
|
const newConfig = state.config;
|
||||||
newConfig.appConfig.language = lang;
|
newConfig.appConfig.language = lang;
|
||||||
@ -271,7 +278,9 @@ const store = new Vuex.Store({
|
|||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
/* Called when app first loaded. Reads config and sets state */
|
/* 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 deepCopy = (json) => JSON.parse(JSON.stringify(json));
|
||||||
const config = deepCopy(new ConfigAccumulator().config());
|
const config = deepCopy(new ConfigAccumulator().config());
|
||||||
commit(SET_CONFIG, config);
|
commit(SET_CONFIG, config);
|
||||||
|
@ -14,11 +14,11 @@ import {
|
|||||||
} from '@/utils/defaults';
|
} from '@/utils/defaults';
|
||||||
import ErrorHandler from '@/utils/ErrorHandler';
|
import ErrorHandler from '@/utils/ErrorHandler';
|
||||||
import { applyItemId } from '@/utils/SectionHelpers';
|
import { applyItemId } from '@/utils/SectionHelpers';
|
||||||
import conf from '../../public/conf.yml';
|
import $store from '../store';
|
||||||
|
|
||||||
export default class ConfigAccumulator {
|
export default class ConfigAccumulator {
|
||||||
constructor() {
|
constructor() {
|
||||||
this.conf = conf;
|
this.conf = $store.state.remoteConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* App Config */
|
/* App Config */
|
||||||
|
@ -42,6 +42,7 @@ module.exports = {
|
|||||||
statusCheck: '/status-check',
|
statusCheck: '/status-check',
|
||||||
save: '/config-manager/save',
|
save: '/config-manager/save',
|
||||||
rebuild: '/config-manager/rebuild',
|
rebuild: '/config-manager/rebuild',
|
||||||
|
getConf: '/config-manager/get',
|
||||||
systemInfo: '/system-info',
|
systemInfo: '/system-info',
|
||||||
corsProxy: '/cors-proxy',
|
corsProxy: '/cors-proxy',
|
||||||
},
|
},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user