From 4e3ecc3b9f78442d0f5896bf98a7f3381704a236 Mon Sep 17 00:00:00 2001 From: Tyler Gottfredsen Date: Thu, 2 Jan 2025 15:34:13 -0600 Subject: [PATCH] Supporting base url configuration --- src/lib/state/state-manager.ts | 8 ++++++-- src/lib/utility/playground-utils.ts | 2 +- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/lib/state/state-manager.ts b/src/lib/state/state-manager.ts index 2282962..54d25e3 100644 --- a/src/lib/state/state-manager.ts +++ b/src/lib/state/state-manager.ts @@ -15,7 +15,11 @@ export class StateManager { logger.debug("encode state"); const encoded = await lzEncode(JSON.stringify(state)); const header: FragmentHeader = "c"; - window.history.replaceState(null, "", window.location.origin + window.location.search); + window.history.replaceState( + null, + "", + window.location.origin + import.meta.env.BASE_URL + window.location.search, + ); window.location.hash = header + encoded; } @@ -25,7 +29,7 @@ export class StateManager { async load(): Promise { checkLegacyParams(); const fragment = StringUtils.trimPrefix(window.location.hash, "#"); - const path = StringUtils.trimPrefix(window.location.pathname, "/"); + const path = StringUtils.trimPrefix(window.location.pathname, import.meta.env.BASE_URL); if (fragment === "" && path === "") { return DEFUALT_STATE; } diff --git a/src/lib/utility/playground-utils.ts b/src/lib/utility/playground-utils.ts index 7723aa8..3ffb1e5 100644 --- a/src/lib/utility/playground-utils.ts +++ b/src/lib/utility/playground-utils.ts @@ -2,7 +2,7 @@ import { DIALECT_CONSTRUCTORS, QUERY_EDITOR_HEADER_DELIMITER } from "../constant export class PlaygroundUtils { static getEntrypointUrl() { - return window.origin + `/playground.js`; + return window.origin + import.meta.env.BASE_URL + `/playground.js`; } static makeQueryEditorHeader(dialect: string) {