Svelte dashboard foundation

Signed-off-by: Romein van Buren <romein@vburen.nl>
This commit is contained in:
Romein van Buren 2022-07-08 13:48:51 +02:00
parent d691ca7f85
commit b265f5565a
Signed by: romein
GPG Key ID: 0EFF8478ADDF6C49
2 changed files with 18 additions and 9 deletions

View File

@ -2,10 +2,11 @@
const { build: viteBuild } = require('vite');
const { svelte } = require('@sveltejs/vite-plugin-svelte');
const fs = require('fs').promises;
module.exports = () => viteBuild({
const build = (prefix = '') => viteBuild({
root: __dirname + '/gui/dashboard',
base: '.',
base: `${prefix}/statusdashboard/asset/`,
plugins: [ svelte() ],
build: {
rollupOptions: {
@ -19,4 +20,7 @@ module.exports = () => viteBuild({
},
});
module.exports();
const cleanup = () => fs.rmdir(__dirname + '/gui/dashboard/build');
module.exports = { build, cleanup };
build();

View File

@ -2,8 +2,7 @@
const { fork } = require('child_process');
const { processOutage } = require('./lib/processoutage');
const buildDashboard = require('./builddashboard');
const fs = require('fs').promises;
const dashboard = require('./dashboard');
const guiCluster = 'web service status';
const icons = {
@ -126,7 +125,8 @@ module.exports = {
settings.autotestInterval = 10;
}
await buildDashboard();
await dashboard.cleanup();
await dashboard.build(server.settings.prefix);
return true;
},
@ -535,9 +535,14 @@ module.exports = {
{ route: '/statusdashboard',
method: 'get',
handler: async (req, res) => {
res.send(
(await fs.readFile(__dirname + '/gui/dashboard/build/index.html')).toString()
);
res.sendFile(__dirname + '/gui/dashboard/build/index.html');
},
},
{ route: '/statusdashboard/asset/:file',
method: 'get',
handler: async (req, res) => {
res.sendFile(__dirname + `/gui/dashboard/build/${req.params[0]}`);
},
},