🪢 Open source agent evals & observability: Trace, evaluate, and improve LLM applications with one open platform.
TypeScript analyticsautogenevaluationlangchainlarge-language-modelsllama-indexllmllm-evaluationllm-observabilityllmopsmonitoringobservabilityopen-sourceopenaiplaygroundprompt-engineeringprompt-managementself-hostedycombinator
fix(web): copy the preview gateway host the certificate covers (#18710)
Tobias Wochinger3fae8f9f9f95
diff --git a/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.clienttest.ts b/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.clienttest.tsnew file mode 100644index 0000000000..7997307596--- /dev/null+++ b/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.clienttest.ts@@ -0,0 +1,34 @@+// @vitest-environment node++import { describe, expect, it } from "vitest";++import { getGatewayBaseUrl } from "@/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl";++describe("getGatewayBaseUrl", () => {+ it("prefixes gateway. onto a product host", () => {+ expect(getGatewayBaseUrl(new URL("https://staging.langfuse.com/"))).toBe(+ "https://gateway.staging.langfuse.com/v1",+ );+ });++ it("uses the single-label preview host the certificate covers", () => {+ expect(+ getGatewayBaseUrl(new URL("https://pr-123.preview.langfuse.com/")),+ ).toBe("https://gateway-pr-123.preview.langfuse.com/v1");+ });++ it.each([+ "pr-abc.preview.langfuse.com",+ "pr-123.preview.langfuse.com.example.org",+ ])("keeps the standard prefix for non-preview host %s", (hostname) => {+ expect(getGatewayBaseUrl(new URL(`https://${hostname}/`))).toBe(+ `https://gateway.${hostname}/v1`,+ );+ });++ it("points localhost at the local gateway port", () => {+ expect(getGatewayBaseUrl(new URL("http://localhost:3000/"))).toBe(+ "http://localhost:8080/v1",+ );+ });+});diff --git a/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.ts b/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.tsindex 063c8462a5..fe6d4739b9 100644--- a/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.ts+++ b/web/src/features/ai-gateway/fns/gatewayUrls/getGatewayBaseUrl.ts@@ -1,5 +1,8 @@const LOCAL_GATEWAY_HOSTS = new Set(["localhost", "127.0.0.1", "[::1]"]);+/** Matches numbered preview hosts that use the certificate-covered gateway hostname. */+const PREVIEW_HOST = /^pr-(\d+)\.preview\.langfuse\.com$/;+export function getGatewayBaseUrl(productBaseUrl: URL) {const gatewayBaseUrl = new URL(productBaseUrl);@@ -7,7 +10,7 @@ export function getGatewayBaseUrl(productBaseUrl: URL) {gatewayBaseUrl.protocol = "http:";gatewayBaseUrl.port = "8080";} else {- gatewayBaseUrl.hostname = `gateway.${gatewayBaseUrl.hostname}`;+ gatewayBaseUrl.hostname = toGatewayHostname(gatewayBaseUrl.hostname);}gatewayBaseUrl.pathname = "/v1";@@ -15,3 +18,12 @@ export function getGatewayBaseUrl(productBaseUrl: URL) {gatewayBaseUrl.hash = "";return gatewayBaseUrl.toString();}++function toGatewayHostname(hostname: string) {+ const previewNumber = PREVIEW_HOST.exec(hostname)?.[1];+ if (previewNumber) {+ return `gateway-pr-${previewNumber}.preview.langfuse.com`;+ }++ return `gateway.${hostname}`;+}