From 0f415144dc81961d119706376cf1d72cf975e6de Mon Sep 17 00:00:00 2001 From: Alice Gaudon Date: Tue, 1 Jun 2021 14:38:53 +0200 Subject: [PATCH] Reorganize many root config parameters --- config/default.json5 | 50 +++++++++++----------- config/production.json5 | 22 +++++----- config/test.json5 | 6 +-- src/auth/magic_link/MagicLinkController.ts | 2 +- src/components/MailComponent.ts | 2 +- src/components/WebSocketServerComponent.ts | 2 +- src/main.ts | 2 +- 7 files changed, 44 insertions(+), 42 deletions(-) diff --git a/config/default.json5 b/config/default.json5 index 652d737..52dbd6f 100644 --- a/config/default.json5 +++ b/config/default.json5 @@ -1,19 +1,39 @@ { + asset_cache: false, + gitlab_webhook_token: 'default', app: { + listen_addr: '127.0.0.1', + port: 4899, + public_url: "http://localhost:4899", + public_websocket_url: "ws://localhost:4899", name: 'Example App', contact_email: 'contact@example.net', display_email_warning: true, }, + auth: { + // Registered accounts need to be approved by an administrator + approval_mode: false, + // 30 days + name_change_wait_period: 2592000000, + }, log: { level: "DEBUG", verbose: true, db_level: "ERROR", }, - public_url: "http://localhost:4899", - public_websocket_url: "ws://localhost:4899", - listen_addr: '127.0.0.1', - port: 4899, - gitlab_webhook_token: 'default', + magic_link: { + validity_period: 20, + }, + mail: { + host: "127.0.0.1", + port: "1025", + secure: false, + username: "", + password: "", + allow_invalid_tls: true, + from: 'contact@example.net', + from_name: 'Example App', + }, mysql: { connectionLimit: 10, host: "localhost", @@ -35,28 +55,8 @@ maxAge: 31557600000, }, }, - mail: { - host: "127.0.0.1", - port: "1025", - secure: false, - username: "", - password: "", - allow_invalid_tls: true, - from: 'contact@example.net', - from_name: 'Example App', - }, view: { cache: false, dev: true, }, - asset_cache: false, - magic_link: { - validity_period: 20, - }, - auth: { - // Registered accounts need to be approved by an administrator - approval_mode: false, - // 30 days - name_change_wait_period: 2592000000, - }, } diff --git a/config/production.json5 b/config/production.json5 index 6d48686..6b74f3c 100644 --- a/config/production.json5 +++ b/config/production.json5 @@ -1,26 +1,28 @@ { + asset_cache: true, + app: { + public_url: "https://swaf.example", + public_websocket_url: "wss://swaf.example", + }, log: { level: "DEV", verbose: false, db_level: "ERROR", }, - public_url: "https://swaf.example", - public_websocket_url: "wss://swaf.example", - session: { - cookie: { - secure: true, - }, + magic_link: { + validity_period: 900, }, mail: { secure: true, allow_invalid_tls: false, }, - magic_link: { - validity_period: 900, + session: { + cookie: { + secure: true, + }, }, view: { cache: true, dev: false, - }, - asset_cache: true, + } } diff --git a/config/test.json5 b/config/test.json5 index 62032b0..53997df 100644 --- a/config/test.json5 +++ b/config/test.json5 @@ -1,4 +1,7 @@ { + auth: { + approval_mode: true, + }, mysql: { host: "localhost", user: "root", @@ -12,7 +15,4 @@ maxAge: 1000, }, }, - auth: { - approval_mode: true, - }, } diff --git a/src/auth/magic_link/MagicLinkController.ts b/src/auth/magic_link/MagicLinkController.ts index f733448..a806227 100644 --- a/src/auth/magic_link/MagicLinkController.ts +++ b/src/auth/magic_link/MagicLinkController.ts @@ -142,7 +142,7 @@ export default class MagicLinkController extends Controll email: link.getOrFail('email'), type: link.getOrFail('action_type'), validUntil: link.getExpirationDate().getTime(), - websocketUrl: config.get('public_websocket_url') + this.magicLinkWebsocketPath, + websocketUrl: config.get('app.public_websocket_url') + this.magicLinkWebsocketPath, }); } diff --git a/src/components/MailComponent.ts b/src/components/MailComponent.ts index 84551c3..ab603e5 100644 --- a/src/components/MailComponent.ts +++ b/src/components/MailComponent.ts @@ -89,7 +89,7 @@ export default class MailComponent extends ApplicationComponent { // Set locals locals.mail_subject = options.subject; locals.mail_to = options.to; - locals.mail_link = config.get('public_url') + + locals.mail_link = config.get('app.public_url') + route('mail', [template.template], locals); Object.assign(locals, this.getApp().as(FrontendToolsComponent).getGlobals().get()); diff --git a/src/components/WebSocketServerComponent.ts b/src/components/WebSocketServerComponent.ts index ec11a64..a9d9efa 100644 --- a/src/components/WebSocketServerComponent.ts +++ b/src/components/WebSocketServerComponent.ts @@ -24,7 +24,7 @@ export default class WebSocketServerComponent extends ApplicationComponent { const globals = app.asOptional(FrontendToolsComponent)?.getGlobals(); if (globals) { - globals.set('websocketUrl', config.get('public_websocket_url')); + globals.set('websocketUrl', config.get('app.public_websocket_url')); } } diff --git a/src/main.ts b/src/main.ts index d7cff2c..edc86ee 100644 --- a/src/main.ts +++ b/src/main.ts @@ -17,7 +17,7 @@ import TestApp from "./TestApp.js"; const packageJson = JSON.parse((await fs.readFile('package.json')).toString()); - const app = new TestApp(packageJson.version, config.get('listen_addr'), config.get('port')); + const app = new TestApp(packageJson.version, config.get('app.listen_addr'), config.get('app.port')); await app.start(); })().catch(err => { logger.error(err);