From cc01e326a74aeb2117a19a9fb112fa4d3a1911a7 Mon Sep 17 00:00:00 2001 From: stevejpurves Date: Tue, 21 Nov 2023 22:37:06 +0000 Subject: [PATCH] =?UTF-8?q?=F0=9F=9B=A0fix=20wsUrl=20bug=20&=20?= =?UTF-8?q?=F0=9F=A4=96=20randomize=20default=20token?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- packages/core/src/options.ts | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/packages/core/src/options.ts b/packages/core/src/options.ts index 29f107a0..7661267e 100644 --- a/packages/core/src/options.ts +++ b/packages/core/src/options.ts @@ -8,6 +8,7 @@ import type { SavedSessionOptions, MathjaxOptions, } from './types'; +import { shortId } from './utils'; export function makeBinderOptions(opts: BinderOptions) { return { @@ -36,12 +37,15 @@ export function makeKernelOptions(opts: KernelOptions): Required } export function makeServerSettings(settings: ServerSettings): Required { + const baseUrl = settings.baseUrl ?? 'http://localhost:8888'; + const wsUrl = settings.wsUrl ?? baseUrl.replace(/^http/, 'ws'); + return { - baseUrl: 'http://localhost:8888', - token: 'test-secret', + token: shortId(), // randomized default token to prevent accidental access to a local server appendToken: true, - wsUrl: 'ws://localhost:8888', ...settings, + wsUrl, + baseUrl, }; }