From eabf46c5cb29d30fa26a5e170f1ab05f45afc5d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=C3=89mile=20R=C3=A9?= Date: Mon, 22 Jun 2026 11:12:55 +0200 Subject: [PATCH] Add HTTP endpoint helpers to compliance-portal MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Introduce a lib/http module with buildEndpoint and getPathPrefix, extracted from the trust app so the compliance portal can resolve its GraphQL endpoint with the same path-prefix handling. Signed-off-by: Émile Ré --- .../src/lib/http/endpoint.ts | 42 +++++++++++++++++++ .../src/lib/http/pathPrefix.ts | 29 +++++++++++++ 2 files changed, 71 insertions(+) create mode 100644 apps/compliance-portal/src/lib/http/endpoint.ts create mode 100644 apps/compliance-portal/src/lib/http/pathPrefix.ts diff --git a/apps/compliance-portal/src/lib/http/endpoint.ts b/apps/compliance-portal/src/lib/http/endpoint.ts new file mode 100644 index 000000000..859188a20 --- /dev/null +++ b/apps/compliance-portal/src/lib/http/endpoint.ts @@ -0,0 +1,42 @@ +// Copyright (c) 2025-2026 Probo Inc . +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +import { getPathPrefix } from "#/lib/http/pathPrefix"; + +export function buildEndpoint(): string { + let host = import.meta.env.VITE_API_URL; + + if (!host) { + host = window.location.origin; + } + + const formattedHost + = host.startsWith("http://") || host.startsWith("https://") + ? host + : `https://${host}`; + + const url = new URL(formattedHost); + + const prefix = getPathPrefix(); + let path: string; + if (prefix) { + path = `${prefix}/api/trust/v1/graphql`; + } else { + path = `/api/trust/v1/graphql`; + } + + url.pathname = path; + + return url.toString(); +} diff --git a/apps/compliance-portal/src/lib/http/pathPrefix.ts b/apps/compliance-portal/src/lib/http/pathPrefix.ts new file mode 100644 index 000000000..d57f5c3d7 --- /dev/null +++ b/apps/compliance-portal/src/lib/http/pathPrefix.ts @@ -0,0 +1,29 @@ +// Copyright (c) 2026 Probo Inc . +// +// Permission to use, copy, modify, and/or distribute this software for any +// purpose with or without fee is hereby granted, provided that the above +// copyright notice and this permission notice appear in all copies. +// +// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH +// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY +// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, +// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM +// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR +// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR +// PERFORMANCE OF THIS SOFTWARE. + +import { matchPath } from "react-router"; + +export function getPathPrefix() { + const match = matchPath( + { path: "/trust/:id", caseSensitive: false, end: false }, + window.location.pathname, + ); + + let prefix = ""; + if (match) { + prefix = `/trust/${match.params.id}`; + } + + return prefix; +}