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; +}