From db3227213bc9bc5db062d97ce4beb62cc85ff507 Mon Sep 17 00:00:00 2001 From: Arnaud Date: Mon, 24 Feb 2025 09:24:03 +0100 Subject: [PATCH] Add api-port get parameter to update the port settings --- src/main.tsx | 43 +++++++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 10 deletions(-) diff --git a/src/main.tsx b/src/main.tsx index 0fe4066..da29709 100644 --- a/src/main.tsx +++ b/src/main.tsx @@ -21,6 +21,7 @@ import { SettingsRoute } from "./routes/dashboard/settings.tsx"; import { HelpRoute } from "./routes/dashboard/help.tsx"; import { DisclaimerRoute } from "./routes/dashboard/disclaimer.tsx"; import { RouteErrorBoundary } from "./components/RouteErrorBoundary/RouteErrorBoundary.tsx"; +import { HealthCheckUtils } from "./components/HealthChecks/health-check.utils.ts"; if (import.meta.env.PROD && !import.meta.env.CI) { Sentry.init({ @@ -117,14 +118,36 @@ const queryClient = new QueryClient(); const rootElement = document.getElementById("root")!; if (rootElement) { - CodexSdk.load().then(() => { - render( - - - - - , - rootElement - ); - }); + CodexSdk.load() + .then(() => { + const queryString = window.location.search; + if (queryString) { + const urlParams = new URLSearchParams(queryString); + const param = urlParams.get("api-port"); + if (param) { + const port = parseInt(param, 10); + if (!isNaN(port)) { + const address = HealthCheckUtils.removePort(CodexSdk.url()); + + const url = address + ":" + port; + + if (HealthCheckUtils.isUrlInvalid(url)) { + return; + } + + return CodexSdk.updateURL(url); + } + } + } + }) + .then(() => { + render( + + + + + , + rootElement + ); + }); }