From 7691085e8f49c70c4300798f281637cd59ec1cdb Mon Sep 17 00:00:00 2001 From: Romein van Buren Date: Wed, 13 Jul 2022 10:27:06 +0200 Subject: [PATCH] Route prefix --- gui/components/formoutagetablefield.svelte | 2 +- gui/dashboard/app.svelte | 2 +- gui/modules/webservicemonitor.svelte | 2 +- gui/modules/webserviceoutages.svelte | 20 ++++++------ gui/modules/webservices.svelte | 20 ++++++------ gui/widgets/webservicestatus.svelte | 2 +- index.js | 36 +++++++++++----------- lib/dashboard/socket.js | 2 +- 8 files changed, 43 insertions(+), 43 deletions(-) diff --git a/gui/components/formoutagetablefield.svelte b/gui/components/formoutagetablefield.svelte index fb216f5..5e35e28 100644 --- a/gui/components/formoutagetablefield.svelte +++ b/gui/components/formoutagetablefield.svelte @@ -45,7 +45,7 @@ function openOutage(title, id) { } onMount(async () => { - outages = (await api.get('/outages')).filter(o => o.services?.includes(service)); + outages = (await api.get('/status/outages')).filter(o => o.services?.includes(service)); }); diff --git a/gui/dashboard/app.svelte b/gui/dashboard/app.svelte index 847ec76..d53656e 100644 --- a/gui/dashboard/app.svelte +++ b/gui/dashboard/app.svelte @@ -88,7 +88,7 @@ onMount(() => { proportionalGrid(); - const ws = new WebSocket('ws://__SERVER__/statusdashboard/socket'); + const ws = new WebSocket('ws://__SERVER__/status/dashboard/socket'); ws.onmessage = async evt => { const data = JSON.parse(evt.data || '""'); diff --git a/gui/modules/webservicemonitor.svelte b/gui/modules/webservicemonitor.svelte index 860a6c4..0868ac5 100644 --- a/gui/modules/webservicemonitor.svelte +++ b/gui/modules/webservicemonitor.svelte @@ -21,7 +21,7 @@ let webservices = []; async function refresh() { console.log('refresh'); try { - webservices = await api.get('/webservices'); + webservices = await api.get('/status/webservices'); } catch (err) { console.error(err); diff --git a/gui/modules/webserviceoutages.svelte b/gui/modules/webserviceoutages.svelte index 57a4d9e..ca94406 100644 --- a/gui/modules/webserviceoutages.svelte +++ b/gui/modules/webserviceoutages.svelte @@ -76,19 +76,19 @@ onMount(async function () { // get item, form and log for specified id try { // get settings, to read previewUrl - settings = await api.get('/outages/settings'); - ({ item, form, log } = isNew ? await api.post('/outages', {}, { init: true }) : await api.get('/outages/' + id)); + settings = await api.get('/status/outages/settings'); + ({ item, form, log } = isNew ? await api.post('/status/outages', {}, { init: true }) : await api.get('/status/outages/' + id)); // if existing item, set tabtitle to title of item if (!isNew) { dispatch('tabchanged', { title: item.name }); } api.subscribe(pluginName + '/reload', async msg => { if (msg.id == item.id) { - ({ item, form, log } = await api.get('/outages' + id)); + ({ item, form, log } = await api.get('/status/outages' + id)); } }); api.subscribe(entity + '/reload', async () => { - ({ form, log } = await api.get('/outages/' + id)); + ({ form, log } = await api.get('/status/outages/' + id)); }); } catch (e) { @@ -99,8 +99,8 @@ onMount(async function () { } } else { - filters = await api.get('/outages/filters'); - gridOptions.columns = await api.get('/outages/formats'); + filters = await api.get('/status/outages/filters'); + gridOptions.columns = await api.get('/status/outages/formats'); // subscribe to 'reload' message api.subscribe(pluginName + '/reload', async () => { multifilter.submit(); @@ -131,8 +131,8 @@ async function saveChanges() { // save changes for outage in form savebar.start(); const result = isNew ? - await api.post('/outages', item) : - await api.put('/outages/' + item.id, item); + await api.post('/status/outages', item) : + await api.put('/status/outages/' + item.id, item); savebar.stop(result); if (!result.errors) { log = result.log; @@ -148,7 +148,7 @@ async function submitFilters({ detail }) { if (grid) { grid.reset(); } - items = await api.post('/outages/search', detail); + items = await api.post('/status/outages/search', detail); } async function deleteItem() { @@ -158,7 +158,7 @@ async function deleteItem() { msg: translate('Are you sure you want to delete this item?', language), }); dispatch('close'); - await api.delete('/outages/' + item.id); + await api.delete('/status/outages/' + item.id); } catch (e) { console.log(e); diff --git a/gui/modules/webservices.svelte b/gui/modules/webservices.svelte index 7f3fd7b..9c6dac4 100644 --- a/gui/modules/webservices.svelte +++ b/gui/modules/webservices.svelte @@ -76,19 +76,19 @@ onMount(async function () { // get item, form and log for specified id try { // get settings, to read previewUrl - settings = await api.get('/webservices/settings'); - ({ item, form, log } = isNew ? await api.post('/webservices', {}, { init: true }) : await api.get('/webservices/' + id)); + settings = await api.get('/status/webservices/settings'); + ({ item, form, log } = isNew ? await api.post('/status/webservices', {}, { init: true }) : await api.get('/status/webservices/' + id)); // if existing item, set tabtitle to title of item if (!isNew) { dispatch('tabchanged', { title: item.name }); } api.subscribe(pluginName + '/reload', async msg => { if (msg.id == item.id) { - ({ item, form, log } = await api.get('/webservices' + id)); + ({ item, form, log } = await api.get('/status/webservices' + id)); } }); api.subscribe(entity + '/reload', async () => { - ({ form, log } = await api.get('/webservices/' + id)); + ({ form, log } = await api.get('/status/webservices/' + id)); }); } catch (e) { @@ -99,8 +99,8 @@ onMount(async function () { } } else { - filters = await api.get('/webservices/filters'); - gridOptions.columns = await api.get('/webservices/formats'); + filters = await api.get('/status/webservices/filters'); + gridOptions.columns = await api.get('/status/webservices/formats'); // subscribe to 'reload' message api.subscribe(pluginName + '/reload', async () => { multifilter.submit(); @@ -131,8 +131,8 @@ async function saveChanges() { // save changes for web service in form savebar.start(); const result = isNew ? - await api.post('/webservices', item) : - await api.put('/webservices/' + item.id, item); + await api.post('/status/webservices', item) : + await api.put('/status/webservices/' + item.id, item); savebar.stop(result); if (!result.errors) { log = result.log; @@ -148,7 +148,7 @@ async function submitFilters({ detail }) { if (grid) { grid.reset(); } - items = await api.post('/webservices/search', detail); + items = await api.post('/status/webservices/search', detail); } async function deleteItem() { @@ -158,7 +158,7 @@ async function deleteItem() { msg: translate('Are you sure you want to delete this item?', language), }); dispatch('close'); - await api.delete('/webservices/' + item.id); + await api.delete('/status/webservices/' + item.id); } catch (e) { console.log(e); diff --git a/gui/widgets/webservicestatus.svelte b/gui/widgets/webservicestatus.svelte index d0ec2fa..f1f0e03 100644 --- a/gui/widgets/webservicestatus.svelte +++ b/gui/widgets/webservicestatus.svelte @@ -18,7 +18,7 @@ const icons = { let promise; async function refresh() { - promise = await api.get('/webservices'); + promise = await api.get('/status/webservices'); } onMount(() => { diff --git a/index.js b/index.js index c4e83f2..a7b9220 100644 --- a/index.js +++ b/index.js @@ -239,7 +239,7 @@ module.exports = { routes: ({ server, settings }) => [ // Get all services - { route: '/webservices', + { route: '/status/webservices', method: 'get', requires: 'smartyellow/status/seeServices', handler: async (req, res, user) => { @@ -270,7 +270,7 @@ module.exports = { }, // Get details for specific service - { route: '/webservices/:id', + { route: '/status/webservices/:id', method: 'get', requires: 'smartyellow/status/seeServices', handler: async (req, res, user) => { @@ -287,7 +287,7 @@ module.exports = { }, }, - { route: '/webservices/search', + { route: '/status/webservices/search', method: 'post', requires: 'smartyellow/status/seeServices', handler: async (req, res, user) => { @@ -302,7 +302,7 @@ module.exports = { }, // Get filters for services - { route: '/webservices/filters', + { route: '/status/webservices/filters', method: 'get', requires: 'smartyellow/status/seeServices', handler: async (req, res, user) => { @@ -314,7 +314,7 @@ module.exports = { }, // Get formats for services - { route: '/webservices/formats', + { route: '/status/webservices/formats', method: 'get', requires: 'smartyellow/status/seeServices', handler: async (req, res, user) => { @@ -327,7 +327,7 @@ module.exports = { }, // Create new service - { route: '/webservices', + { route: '/status/webservices', method: 'post', requires: 'smartyellow/status/createServices', handler: async (req, res, user) => { @@ -353,7 +353,7 @@ module.exports = { }, // Update existing service - { route: '/webservices/:id', + { route: '/status/webservices/:id', method: 'put', requires: 'smartyellow/status/editServices', handler: async (req, res, user) => { @@ -380,7 +380,7 @@ module.exports = { }, // Delete specific service - { route: '/webservices/:id', + { route: '/status/webservices/:id', method: 'delete', requires: 'smartyellow/status/deleteServices', handler: async (req, res, user) => { @@ -396,7 +396,7 @@ module.exports = { }, // Get all outages - { route: '/outages', + { route: '/status/outages', method: 'get', requires: 'smartyellow/status/seeOutages', handler: async (req, res, user) => { @@ -407,7 +407,7 @@ module.exports = { }, // Get details for specific outage - { route: '/outages/:id', + { route: '/status/outages/:id', method: 'get', requires: 'smartyellow/status/seeOutages', handler: async (req, res, user) => { @@ -424,7 +424,7 @@ module.exports = { }, }, - { route: '/outages/search', + { route: '/status/outages/search', method: 'post', requires: 'smartyellow/status/seeOutages', handler: async (req, res, user) => { @@ -439,7 +439,7 @@ module.exports = { }, // Get filters for outages - { route: '/outages/filters', + { route: '/status/outages/filters', method: 'get', requires: 'smartyellow/status/seeOutages', handler: async (req, res, user) => { @@ -451,7 +451,7 @@ module.exports = { }, // Get formats for outages - { route: '/outages/formats', + { route: '/status/outages/formats', method: 'get', requires: 'smartyellow/status/seeOutages', handler: async (req, res, user) => { @@ -464,7 +464,7 @@ module.exports = { }, // Create new service - { route: '/outages', + { route: '/status/outages', method: 'post', requires: 'smartyellow/status/createOutages', handler: async (req, res, user) => { @@ -490,7 +490,7 @@ module.exports = { }, // Update existing service - { route: '/outages/:id', + { route: '/status/outages/:id', method: 'put', requires: 'smartyellow/status/editOutages', handler: async (req, res, user) => { @@ -517,7 +517,7 @@ module.exports = { }, // Delete specific service - { route: '/outages/:id', + { route: '/status/outages/:id', method: 'delete', requires: 'smartyellow/status/deleteOutages', handler: async (req, res, user) => { @@ -532,7 +532,7 @@ module.exports = { }, }, - { route: '/statusdashboard', + { route: '/status/dashboard', method: 'get', handler: async (req, res) => { try { @@ -569,7 +569,7 @@ module.exports = { }, }, - { route: '/statusdashboard/sound', + { route: '/status/dashboard/sound', method: 'get', handler: (req, res) => { res.headers['content-type'] = 'audio/x-wav'; diff --git a/lib/dashboard/socket.js b/lib/dashboard/socket.js index 80c19f9..83f10d5 100644 --- a/lib/dashboard/socket.js +++ b/lib/dashboard/socket.js @@ -17,7 +17,7 @@ const mapService = (s, beat) => ({ async function createDashboardSocket(server) { uws = server.ws({ - route: '/statusdashboard/socket', + route: '/status/dashboard/socket', onOpen: async ws => { async function sendStatuses() { const services = await server.storage