mirror of
https://github.com/Lissy93/dashy.git
synced 2024-12-24 01:12:06 +03:00
⚡ Use constants for API endpoints
This commit is contained in:
parent
17402fb8f7
commit
f0449969e7
17
server.js
17
server.js
@ -17,12 +17,15 @@ const bodyParser = require('body-parser');
|
||||
require('./services/update-checker'); // Checks if there are any updates available, prints message
|
||||
require('./services/config-validator'); // Include and kicks off the config file validation script
|
||||
|
||||
/* Include helper functions and route handlers */
|
||||
const pingUrl = require('./services/ping'); // Used by the status check feature, to ping services
|
||||
/* Include route handlers for API endpoints */
|
||||
const statusCheck = require('./services/status-check'); // Used by the status check feature, to ping services
|
||||
const saveConfig = require('./services/save-config'); // Saves users new conf.yml to file-system
|
||||
const printMessage = require('./services/print-message'); // Function to print welcome msg on start
|
||||
const rebuild = require('./services/rebuild-app'); // A script to programmatically trigger a build
|
||||
|
||||
/* Helper functions, and default config */
|
||||
const printMessage = require('./services/print-message'); // Function to print welcome msg on start
|
||||
const ENDPOINTS = require('./src/utils/defaults').serviceEndpoints; // API endpoint URL paths
|
||||
|
||||
/* Checks if app is running within a container, from env var */
|
||||
const isDocker = !!process.env.IS_DOCKER;
|
||||
|
||||
@ -59,9 +62,9 @@ try {
|
||||
// During build, a custom page will be served before the app is available
|
||||
.use(serveStatic(`${__dirname}/public`, { index: 'default.html' }))
|
||||
// This root returns the status of a given service - used for uptime monitoring
|
||||
.use('/ping', (req, res) => {
|
||||
.use(ENDPOINTS.statusCheck, (req, res) => {
|
||||
try {
|
||||
pingUrl(req.url, async (results) => {
|
||||
statusCheck(req.url, async (results) => {
|
||||
await res.end(results);
|
||||
});
|
||||
} catch (e) {
|
||||
@ -69,7 +72,7 @@ try {
|
||||
}
|
||||
})
|
||||
// POST Endpoint used to save config, by writing conf.yml to disk
|
||||
.use('/config-manager/save', method('POST', (req, res) => {
|
||||
.use(ENDPOINTS.save, method('POST', (req, res) => {
|
||||
try {
|
||||
saveConfig(req.body, (results) => {
|
||||
res.end(results);
|
||||
@ -79,7 +82,7 @@ try {
|
||||
}
|
||||
}))
|
||||
// GET endpoint to trigger a build, and respond with success status and output
|
||||
.use('/config-manager/rebuild', (req, res) => {
|
||||
.use(ENDPOINTS.rebuild, (req, res) => {
|
||||
rebuild().then((response) => {
|
||||
res.end(JSON.stringify(response));
|
||||
}).catch((response) => {
|
||||
|
@ -64,7 +64,7 @@ import VJsoneditor from 'v-jsoneditor';
|
||||
import ErrorHandler, { InfoHandler } from '@/utils/ErrorHandler';
|
||||
import configSchema from '@/utils/ConfigSchema.json';
|
||||
import JsonToYaml from '@/utils/JsonToYaml';
|
||||
import { localStorageKeys } from '@/utils/defaults';
|
||||
import { localStorageKeys, serviceEndpoints } from '@/utils/defaults';
|
||||
import { isUserAdmin } from '@/utils/Auth';
|
||||
|
||||
export default {
|
||||
@ -121,7 +121,7 @@ export default {
|
||||
const yaml = this.jsonParser(this.jsonData);
|
||||
// 2. Prepare the request
|
||||
const baseUrl = process.env.VUE_APP_DOMAIN || window.location.origin;
|
||||
const endpoint = `${baseUrl}/config-manager/save`;
|
||||
const endpoint = `${baseUrl}${serviceEndpoints.save}`;
|
||||
const headers = { 'Content-Type': 'text/plain' };
|
||||
const body = { config: yaml, timestamp: new Date() };
|
||||
const request = axios.post(endpoint, body, headers);
|
||||
|
@ -48,10 +48,10 @@
|
||||
import axios from 'axios';
|
||||
import ProgressBar from 'rsup-progress';
|
||||
import Button from '@/components/FormElements/Button';
|
||||
import { modalNames } from '@/utils/defaults';
|
||||
import RebuildIcon from '@/assets/interface-icons/application-rebuild.svg';
|
||||
import ReloadIcon from '@/assets/interface-icons/application-reload.svg';
|
||||
import LoadingAnimation from '@/assets/interface-icons/loader.svg';
|
||||
import { modalNames, serviceEndpoints } from '@/utils/defaults';
|
||||
|
||||
export default {
|
||||
name: 'RebuildApp',
|
||||
@ -76,7 +76,7 @@ export default {
|
||||
/* Calls to the rebuild endpoint, to kickoff the app build */
|
||||
startBuild() {
|
||||
const baseUrl = process.env.VUE_APP_DOMAIN || window.location.origin;
|
||||
const endpoint = `${baseUrl}/config-manager/rebuild`;
|
||||
const endpoint = `${baseUrl}${serviceEndpoints.rebuild}`;
|
||||
this.loading = true;
|
||||
this.progress.start();
|
||||
axios.get(endpoint)
|
||||
|
@ -49,7 +49,7 @@ import Icon from '@/components/LinkItems/ItemIcon.vue';
|
||||
import ItemOpenMethodIcon from '@/components/LinkItems/ItemOpenMethodIcon';
|
||||
import StatusIndicator from '@/components/LinkItems/StatusIndicator';
|
||||
import ContextMenu from '@/components/LinkItems/ContextMenu';
|
||||
import { localStorageKeys } from '@/utils/defaults';
|
||||
import { localStorageKeys, serviceEndpoints } from '@/utils/defaults';
|
||||
|
||||
export default {
|
||||
name: 'Item',
|
||||
@ -173,7 +173,7 @@ export default {
|
||||
// Deterimine if user disabled security
|
||||
const enableInsecure = statusCheckAllowInsecure ? '&enableInsecure=true' : '';
|
||||
// Construct the full API endpoint's URL with GET params
|
||||
return `${baseUrl}/ping/${urlToCheck}${headers}${enableInsecure}`;
|
||||
return `${baseUrl}${serviceEndpoints.statusCheck}/${urlToCheck}${headers}${enableInsecure}`;
|
||||
},
|
||||
/* Checks if a given service is currently online */
|
||||
checkWebsiteStatus() {
|
||||
|
Loading…
Reference in New Issue
Block a user