From 0e7c55f7ab8d496e81a3dbd53f14e0c46cb27fa6 Mon Sep 17 00:00:00 2001 From: Kristóf Marussy Date: Mon, 4 Sep 2023 18:08:59 +0200 Subject: refactor: server environemntal variables * Prefix each variable with REFINERY_ * If not public host is specified, allow all origings and compute the WebSocket address on the client from the origin. --- subprojects/frontend/config/detectDevModeOptions.ts | 4 ++-- subprojects/frontend/src/xtext/BackendConfig.ts | 2 +- subprojects/frontend/src/xtext/XtextWebSocketClient.ts | 5 ++++- 3 files changed, 7 insertions(+), 4 deletions(-) (limited to 'subprojects/frontend') diff --git a/subprojects/frontend/config/detectDevModeOptions.ts b/subprojects/frontend/config/detectDevModeOptions.ts index 665204dc..6052e047 100644 --- a/subprojects/frontend/config/detectDevModeOptions.ts +++ b/subprojects/frontend/config/detectDevModeOptions.ts @@ -30,8 +30,8 @@ function detectListenOptions( fallbackHost: string, fallbackPort: number, ): ListenOptions { - const host = process.env[`${name}_HOST`] ?? fallbackHost; - const rawPort = process.env[`${name}_PORT`]; + const host = process.env[`REFINERY_${name}_HOST`] ?? fallbackHost; + const rawPort = process.env[`REFINERY_${name}_PORT`]; const port = rawPort === undefined ? fallbackPort : parseInt(rawPort, 10); const secure = port === 443; return { host, port, secure }; diff --git a/subprojects/frontend/src/xtext/BackendConfig.ts b/subprojects/frontend/src/xtext/BackendConfig.ts index 4c7eac5f..e7043bd5 100644 --- a/subprojects/frontend/src/xtext/BackendConfig.ts +++ b/subprojects/frontend/src/xtext/BackendConfig.ts @@ -11,7 +11,7 @@ import { z } from 'zod'; export const ENDPOINT = 'config.json'; const BackendConfig = z.object({ - webSocketURL: z.string().url(), + webSocketURL: z.string().url().optional(), }); type BackendConfig = z.infer; diff --git a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts index 6bb7eec8..963c1d4c 100644 --- a/subprojects/frontend/src/xtext/XtextWebSocketClient.ts +++ b/subprojects/frontend/src/xtext/XtextWebSocketClient.ts @@ -282,7 +282,10 @@ export default class XtextWebSocketClient { log.debug('Creating WebSocket'); (async () => { - const { webSocketURL } = await fetchBackendConfig(); + let { webSocketURL } = await fetchBackendConfig(); + if (webSocketURL === undefined) { + webSocketURL = `${window.origin.replace(/^http/, 'ws')}/xtext-service`; + } this.openWebSocketWithURL(webSocketURL); })().catch((error) => { log.error('Error while initializing connection', error); -- cgit v1.2.3-54-g00ecf