Skip to content

armgit / dashy

Public Imported from GitHub
0

πŸš€ A self-hostable personal dashboard built for you. Includes status-checking, widgets, themes, icon packs, a UI editor and tons more!

🚚 Moves / organises service utils into sub-directories

Alicia Sykes463930689b7a
diff --git a/docs/authentication/authentik.md b/docs/authentication/authentik.md
index 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, whic
To 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.md
index 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 still
Server-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.md
index 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 frequent
If 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.json
index 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.js
index 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.js
index 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.js
similarity index 95%
rename from services/api/config-files.js
rename to services/endpoints/api/config-files.js
index 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.js
similarity index 100%
rename from services/api/index.js
rename to services/endpoints/api/index.js
diff --git a/services/api/openapi.yml b/services/endpoints/api/openapi.yml
similarity index 100%
rename from services/api/openapi.yml
rename to services/endpoints/api/openapi.yml
diff --git a/services/cors-proxy.js b/services/endpoints/cors-proxy.js
similarity index 98%
rename from services/cors-proxy.js
rename to services/endpoints/cors-proxy.js
index 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 set
diff --git a/services/get-user.js b/services/endpoints/get-user.js
similarity index 100%
rename from services/get-user.js
rename to services/endpoints/get-user.js
diff --git a/services/ping-check.js b/services/endpoints/ping-check.js
similarity index 100%
rename from services/ping-check.js
rename to services/endpoints/ping-check.js
diff --git a/services/save-config.js b/services/endpoints/save-config.js
similarity index 100%
rename from services/save-config.js
rename to services/endpoints/save-config.js
diff --git a/services/status-check.js b/services/endpoints/status-check.js
similarity index 99%
rename from services/status-check.js
rename to services/endpoints/status-check.js
index 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.js
similarity index 100%
rename from services/system-info.js
rename to services/endpoints/system-info.js
diff --git a/services/serverless-functions/cloud-status-check.js b/services/serverless-functions/cloud-status-check.js
index 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.js
index 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 data
diff --git a/services/auth-oidc.js b/services/utils/auth-oidc.js
similarity index 100%
rename from services/auth-oidc.js
rename to services/utils/auth-oidc.js
diff --git a/services/config-validator.js b/services/utils/config-validator.js
similarity index 95%
rename from services/config-validator.js
rename to services/utils/config-validator.js
index 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 path
const yaml = require('./yaml'); // For parsing YAML
const 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.js
similarity index 100%
rename from services/print-message.js
rename to services/utils/print-message.js
diff --git a/services/request.js b/services/utils/request.js
similarity index 100%
rename from services/request.js
rename to services/utils/request.js
diff --git a/services/ssl-server.js b/services/utils/ssl-server.js
similarity index 100%
rename from services/ssl-server.js
rename to services/utils/ssl-server.js
diff --git a/services/update-checker.js b/services/utils/update-checker.js
similarity index 96%
rename from services/update-checker.js
rename to services/utils/update-checker.js
index 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.js
similarity index 100%
rename from services/yaml.js
rename to services/utils/yaml.js
diff --git a/tests/components/item.test.js b/tests/components/item.test.js
index 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.js
index 29515937..3c76b739 100644
--- a/tests/server/auth-oidc.test.js
+++ b/tests/server/auth-oidc.test.js
@@ -1,6 +1,6 @@
// @vitest-environment node
import { 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.js
index 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.js
index 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.js
index 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.js
index 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;