From f8fa3b0ba26b6f6e4c843355365424e461a869da Mon Sep 17 00:00:00 2001 From: bludnic Date: Sun, 21 Jan 2024 16:53:51 +0000 Subject: [PATCH] chore(tRPC): customize backend URL in production without rebuilding the image --- apps/frontend/src/lib/trpc/getBaseUrl.ts | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/apps/frontend/src/lib/trpc/getBaseUrl.ts b/apps/frontend/src/lib/trpc/getBaseUrl.ts index b52ba8cb..470368ef 100644 --- a/apps/frontend/src/lib/trpc/getBaseUrl.ts +++ b/apps/frontend/src/lib/trpc/getBaseUrl.ts @@ -1,4 +1,14 @@ export function getBaseUrl(): string { + const isProduction = process.env.NODE_ENV === "production"; + if (isProduction) { + if (typeof window !== "undefined") { + const customURL = localStorage.getItem("APP_URL"); + + // browser should use relative path + return customURL ? customURL : ""; + } + } + if (process.env.NEXT_PUBLIC_PROCESSOR_ENABLE_TRPC) { return `${process.env.NEXT_PUBLIC_PROCESSOR_URL}`; }