π A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!
Vue awesomedashboarddockerhomelabhomepagemitnodejsorganizationproductivitypwaself-hostedstartpagevue
π Moves / organises service utils into sub-directories
Alicia Sykes463930689b7a
diff --git a/docs/authentication/authentik.md b/docs/authentication/authentik.mdindex 95ce9ec8..b728085c 100644--- a/docs/authentication/authentik.md+++ b/docs/authentication/authentik.md@@ -400,4 +400,4 @@ When the token expires you're bounced back through Authentik for a new one, whicTo sign out, use Dashy's Logout control: it clears the stored token and sends you to Authentik's end-session endpoint (see [Logout stuck on a consent screen](#logout-stuck-on-a-consent-screen) if that asks for confirmation).-If you want the implementation details, the client side lives in `src/utils/auth/OidcAuth.js` and the server-side token verification in `services/auth-oidc.js`.+If you want the implementation details, the client side lives in `src/utils/auth/OidcAuth.js` and the server-side token verification in `services/utils/auth-oidc.js`.diff --git a/docs/authentication/header-auth.md b/docs/authentication/header-auth.mdindex c3ba0f11..a6df4c7d 100644--- a/docs/authentication/header-auth.md+++ b/docs/authentication/header-auth.md@@ -215,4 +215,4 @@ Expected with the default config. Logout clears Dashy's cookie, but you're stillServer-side, the same proxy-whitelist middleware guards the config and API routes, so a request from an untrusted IP is rejected before it reaches anything. Writes (saving config) additionally require the matched user to be `type: admin`.-The relevant code is `src/utils/auth/HeaderAuth.js` on the frontend, and `services/app.js` with `services/get-user.js` on the server.+The relevant code is `src/utils/auth/HeaderAuth.js` on the frontend, and `services/app.js` with `services/endpoints/get-user.js` on the server.diff --git a/docs/widgets.md b/docs/widgets.mdindex 2d71555a..dd66cb54 100644--- a/docs/widgets.md+++ b/docs/widgets.md@@ -3548,7 +3548,7 @@ Note that if you have many widgets, and set them to continuously update frequentIf a widget fails to make a data request, and the console shows a CORS error, this means the server is blocking client-side requests.-Dashy has a built-in CORS proxy ([`services/cors-proxy.js`](https://github.com/Lissy93/dashy/blob/master/services/cors-proxy.js)), which will be used automatically by some widgets, or can be forced to use by other by setting the `useProxy` option.+Dashy has a built-in CORS proxy ([`services/endpoints/cors-proxy.js`](https://github.com/Lissy93/dashy/blob/master/services/endpoints/cors-proxy.js)), which will be used automatically by some widgets, or can be forced to use by other by setting the `useProxy` option.For example:diff --git a/package.json b/package.jsonindex 86032407..14a63d8a 100644--- a/package.json+++ b/package.json@@ -17,7 +17,7 @@"test:ui": "vitest --ui","test:coverage": "vitest run --coverage","pm2-start": "npx pm2 start server.js",- "validate-config": "node services/config-validator",+ "validate-config": "node services/utils/config-validator","health-check": "node services/healthcheck","dependency-audit": "npx improved-yarn-audit --ignore-dev-deps"},diff --git a/server.js b/server.jsindex 2ce4779d..24bf380d 100644--- a/server.js+++ b/server.js@@ -10,8 +10,8 @@ const os = require('os');const http = require('http');const app = require('./services/app');-const sslServer = require('./services/ssl-server');-const printMessage = require('./services/print-message');+const sslServer = require('./services/utils/ssl-server');+const printMessage = require('./services/utils/print-message');/* Checks if app is running within a container, from env var */const isDocker = !!process.env.IS_DOCKER;diff --git a/services/app.js b/services/app.jsindex 9e248d21..508ea17d 100644--- a/services/app.js+++ b/services/app.js@@ -12,28 +12,28 @@ const crypto = require('crypto');const rootDir = path.join(__dirname, '..');/* Import NPM dependencies */-const yaml = require('./yaml');+const yaml = require('./utils/yaml');/* Import Express + middleware functions */const express = require('express');const basicAuth = require('express-basic-auth');/* Kick of some basic checks */-require('./update-checker'); // Checks if there are any updates available, prints message+require('./utils/update-checker'); // Checks if there are any updates available, prints message-let config = require('./config-validator'); // Validate config file and load result+let config = require('./utils/config-validator'); // Validate config file and load result/* Include route handlers for API endpoints */-const statusCheck = require('./status-check'); // Used by the status check feature, uses GET-const pingCheck = require('./ping-check'); // Used by the ping check feature, uses GET-const saveConfig = require('./save-config'); // Saves users new conf.yml to file-system-const systemInfo = require('./system-info'); // Basic system info, for resource widget-const sslServer = require('./ssl-server'); // TLS-enabled web server-const corsProxy = require('./cors-proxy'); // Enables API requests to CORS-blocked services-const getUser = require('./get-user'); // Enables server side user lookup-const { apiEnabledGate, apiErrorHandler, createApiRouter } = require('./api'); // Opt-in REST API+const statusCheck = require('./endpoints/status-check'); // Used by the status check feature, uses GET+const pingCheck = require('./endpoints/ping-check'); // Used by the ping check feature, uses GET+const saveConfig = require('./endpoints/save-config'); // Saves users new conf.yml to file-system+const systemInfo = require('./endpoints/system-info'); // Basic system info, for resource widget+const sslServer = require('./utils/ssl-server'); // TLS-enabled web server+const corsProxy = require('./endpoints/cors-proxy'); // Enables API requests to CORS-blocked services+const getUser = require('./endpoints/get-user'); // Enables server side user lookup+const { apiEnabledGate, apiErrorHandler, createApiRouter } = require('./endpoints/api'); // Opt-in REST API-const { loadOidcSettings, createOidcMiddleware, maybeBootstrapConfig } = require('./auth-oidc');+const { loadOidcSettings, createOidcMiddleware, maybeBootstrapConfig } = require('./utils/auth-oidc');/* Service endpoint URL paths (see also serviceEndpoints in src/utils/config/defaults.js) */const ENDPOINTS = {diff --git a/services/api/config-files.js b/services/endpoints/api/config-files.jssimilarity index 95%rename from services/api/config-files.jsrename to services/endpoints/api/config-files.jsindex 32a8eb2f..d17454c4 100644--- a/services/api/config-files.js+++ b/services/endpoints/api/config-files.js@@ -4,13 +4,13 @@*/const fsPromises = require('fs').promises;const path = require('path');-const yaml = require('../yaml');+const yaml = require('../../utils/yaml');const Ajv = require('ajv');const saveConfig = require('../save-config');-const schema = require('../../src/utils/config/ConfigSchema.json');+const schema = require('../../../src/utils/config/ConfigSchema.json');-const rootDir = path.join(__dirname, '..', '..');+const rootDir = path.join(__dirname, '..', '..', '..');// Same rules as save-config.js: no path separators, control chars or ..const SAFE_FILENAME = /^(?!\.+$)[^\\/\0\r\n]+\.ya?ml$/i;diff --git a/services/api/index.js b/services/endpoints/api/index.jssimilarity index 100%rename from services/api/index.jsrename to services/endpoints/api/index.jsdiff --git a/services/api/openapi.yml b/services/endpoints/api/openapi.ymlsimilarity index 100%rename from services/api/openapi.ymlrename to services/endpoints/api/openapi.ymldiff --git a/services/cors-proxy.js b/services/endpoints/cors-proxy.jssimilarity index 98%rename from services/cors-proxy.jsrename to services/endpoints/cors-proxy.jsindex e90ac2f2..fdf19056 100644--- a/services/cors-proxy.js+++ b/services/endpoints/cors-proxy.js@@ -4,7 +4,7 @@* makes request to endpoint, then responds to the frontend with the response*/-const request = require('./request');+const request = require('../utils/request');const { validateTargetUrl } = request;// If reference to env var is present, substitute for env var value if setdiff --git a/services/get-user.js b/services/endpoints/get-user.jssimilarity index 100%rename from services/get-user.jsrename to services/endpoints/get-user.jsdiff --git a/services/ping-check.js b/services/endpoints/ping-check.jssimilarity index 100%rename from services/ping-check.jsrename to services/endpoints/ping-check.jsdiff --git a/services/save-config.js b/services/endpoints/save-config.jssimilarity index 100%rename from services/save-config.jsrename to services/endpoints/save-config.jsdiff --git a/services/status-check.js b/services/endpoints/status-check.jssimilarity index 99%rename from services/status-check.jsrename to services/endpoints/status-check.jsindex 47dd639c..d509fc86 100644--- a/services/status-check.js+++ b/services/endpoints/status-check.js@@ -3,7 +3,7 @@* It accepts a single url parameter, and will make an empty GET request to that* endpoint, and then resolve the response status code, time taken, and short message*/-const request = require('./request');+const request = require('../utils/request');const { validateTargetUrl } = request;/* Determines if successful from the HTTP response code */diff --git a/services/system-info.js b/services/endpoints/system-info.jssimilarity index 100%rename from services/system-info.jsrename to services/endpoints/system-info.jsdiff --git a/services/serverless-functions/cloud-status-check.js b/services/serverless-functions/cloud-status-check.jsindex 4959bc93..be177396 100644--- a/services/serverless-functions/cloud-status-check.js+++ b/services/serverless-functions/cloud-status-check.js@@ -1,5 +1,5 @@/* A cloud function that wraps the status checking method, for use on Netlify */-const statusCheck = require('../status-check');+const statusCheck = require('../endpoints/status-check');exports.handler = (event, context, callback) => {const paramStr = event.rawQuery;diff --git a/services/serverless-functions/netlify-cors.js b/services/serverless-functions/netlify-cors.jsindex ed8e659d..733408fa 100644--- a/services/serverless-functions/netlify-cors.js+++ b/services/serverless-functions/netlify-cors.js@@ -1,5 +1,5 @@/* A Netlify cloud function to handle requests to CORS-disabled services */-const request = require('../request');+const request = require('../utils/request');exports.handler = (event, context, callback) => {// Get input datadiff --git a/services/auth-oidc.js b/services/utils/auth-oidc.jssimilarity index 100%rename from services/auth-oidc.jsrename to services/utils/auth-oidc.jsdiff --git a/services/config-validator.js b/services/utils/config-validator.jssimilarity index 95%rename from services/config-validator.jsrename to services/utils/config-validator.jsindex df5280a3..61885ed5 100644--- a/services/config-validator.js+++ b/services/utils/config-validator.js@@ -8,7 +8,7 @@ const path = require('path'); // For resolving the config file pathconst yaml = require('./yaml'); // For parsing YAMLconst Ajv = require('ajv'); // For validating with schema-const schema = require('../src/utils/config/ConfigSchema.json');+const schema = require('../../src/utils/config/ConfigSchema.json');/* Tell AJV to use strict mode, and report all errors */const validatorOptions = {@@ -102,7 +102,7 @@ const printFileReadError = (e) => {let config = {};try { // Try to open and parse the YAML file- const confPath = path.resolve(__dirname, '..', process.env.USER_DATA_DIR || 'user-data', 'conf.yml');+ const confPath = path.resolve(__dirname, '..', '..', process.env.USER_DATA_DIR || 'user-data', 'conf.yml');config = yaml.load(fs.readFileSync(confPath, 'utf8'));validate(config);} catch (e) { // Something went very wrong...diff --git a/services/print-message.js b/services/utils/print-message.jssimilarity index 100%rename from services/print-message.jsrename to services/utils/print-message.jsdiff --git a/services/request.js b/services/utils/request.jssimilarity index 100%rename from services/request.jsrename to services/utils/request.jsdiff --git a/services/ssl-server.js b/services/utils/ssl-server.jssimilarity index 100%rename from services/ssl-server.jsrename to services/utils/ssl-server.jsdiff --git a/services/update-checker.js b/services/utils/update-checker.jssimilarity index 96%rename from services/update-checker.jsrename to services/utils/update-checker.jsindex 63f8094e..b6b4dedd 100644--- a/services/update-checker.js+++ b/services/utils/update-checker.js@@ -1,6 +1,6 @@const request = require('./request');-const currentVersion = require('../package.json').version;+const currentVersion = require('../../package.json').version;const packageUrl = 'https://raw.githubusercontent.com/Lissy93/dashy/master/package.json';diff --git a/services/yaml.js b/services/utils/yaml.jssimilarity index 100%rename from services/yaml.jsrename to services/utils/yaml.jsdiff --git a/tests/components/item.test.js b/tests/components/item.test.jsindex ca5aa119..484fa486 100644--- a/tests/components/item.test.js+++ b/tests/components/item.test.js@@ -5,7 +5,7 @@ import { shallowMount } from '@vue/test-utils';import { createStore } from 'vuex';import Item from '@/components/LinkItems/Item.vue';import router from '@/router';-import pingCheck from '../../services/ping-check';+import pingCheck from '../../services/endpoints/ping-check';vi.mock('@/utils/request', () => {const fn = vi.fn(() => Promise.resolve({ data: {} }));diff --git a/tests/server/auth-oidc.test.js b/tests/server/auth-oidc.test.jsindex 29515937..3c76b739 100644--- a/tests/server/auth-oidc.test.js+++ b/tests/server/auth-oidc.test.js@@ -1,6 +1,6 @@// @vitest-environment nodeimport { describe, it, expect } from 'vitest';-import { deriveIsAdmin, loadOidcSettings } from '../../services/auth-oidc';+import { deriveIsAdmin, loadOidcSettings } from '../../services/utils/auth-oidc';const oidc = { kind: 'oidc', clientId: 'dashy', adminGroup: 'admins', adminRole: null };const keycloak = { kind: 'keycloak', clientId: 'dashy', adminGroup: null, adminRole: 'admin' };diff --git a/tests/server/conf-no-server-check.test.js b/tests/server/conf-no-server-check.test.jsindex 13087620..ab23841d 100644--- a/tests/server/conf-no-server-check.test.js+++ b/tests/server/conf-no-server-check.test.js@@ -31,7 +31,7 @@ beforeAll(() => {fs.writeFileSync(path.join(tmpDir, 'sub.yml'), 'pageInfo:\n title: Sub\n');process.env.USER_DATA_DIR = tmpDir;delete require.cache[require.resolve('../../services/app')];- delete require.cache[require.resolve('../../services/auth-oidc')];+ delete require.cache[require.resolve('../../services/utils/auth-oidc')];app = require('../../services/app');});diff --git a/tests/server/conf-strip.test.js b/tests/server/conf-strip.test.jsindex b5b85edd..ff433465 100644--- a/tests/server/conf-strip.test.js+++ b/tests/server/conf-strip.test.js@@ -35,7 +35,7 @@ beforeAll(() => {fs.writeFileSync(path.join(tmpDir, 'sub.yaml'), 'pageInfo:\n title: Sub\n');process.env.USER_DATA_DIR = tmpDir;delete require.cache[require.resolve('../../services/app')];- delete require.cache[require.resolve('../../services/auth-oidc')];+ delete require.cache[require.resolve('../../services/utils/auth-oidc')];app = require('../../services/app');});diff --git a/tests/server/cors-proxy.test.js b/tests/server/cors-proxy.test.jsindex 274c3d54..bb3db148 100644--- a/tests/server/cors-proxy.test.js+++ b/tests/server/cors-proxy.test.js@@ -14,7 +14,7 @@ const tmpDir = fs.mkdtempSync(path.join(os.tmpdir(), 'dashy-cors-test-'));process.env.USER_DATA_DIR = tmpDir;const app = require('../../services/app');-const { substituteEnv } = require('../../services/cors-proxy');+const { substituteEnv } = require('../../services/endpoints/cors-proxy');describe('CORS proxy', () => {it('rejects missing Target-URL', async () => {@@ -182,7 +182,7 @@ describe('CORS proxy error classification', () => {// classifies via a `timeout: true` marker on the RequestError, not via the// 'ECONNABORTED' string (which collides with a real libuv errno).describe('request.js timeout marker', () => {- const request_ = require('../../services/request');+ const request_ = require('../../services/utils/request');let target;let targetUrl;diff --git a/tests/unit/config-validator.test.js b/tests/unit/config-validator.test.jsindex 6cc71261..8e88f94d 100644--- a/tests/unit/config-validator.test.js+++ b/tests/unit/config-validator.test.js@@ -4,7 +4,7 @@ import {import path from 'path';describe('Config Validator', () => {- const configValidator = path.resolve(__dirname, '../../services/config-validator.js');+ const configValidator = path.resolve(__dirname, '../../services/utils/config-validator.js');beforeEach(() => {delete process.env.VUE_APP_CONFIG_VALID;