Skip to content

Commit 30f9938

Browse files
committed
Improve the getBaseUrl function
1 parent 47abf94 commit 30f9938

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cli/template/extras/src/trpc/react.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ export function TRPCReactProvider(props: { children: React.ReactNode }) {
5151
}),
5252
httpBatchStreamLink({
5353
transformer: SuperJSON,
54-
url: getBaseUrl() + "/api/trpc",
54+
url: `${getBaseUrl()}/api/trpc`,
5555
headers: () => {
5656
const headers = new Headers();
5757
headers.set("x-trpc-source", "nextjs-react");
@@ -73,6 +73,10 @@ export function TRPCReactProvider(props: { children: React.ReactNode }) {
7373

7474
function getBaseUrl() {
7575
if (typeof window !== "undefined") return window.location.origin;
76-
if (process.env.VERCEL_URL) return `https://${process.env.VERCEL_URL}`;
76+
if (process.env.VERCEL_URL) {
77+
if (process.env.VERCEL_ENV === "production")
78+
return `https://${process.env.NEXT_PUBLIC_VERCEL_PROJECT_PRODUCTION_URL}`;
79+
return `https://${process.env.VERCEL_URL}`;
80+
}
7781
return `http://localhost:${process.env.PORT ?? 3000}`;
7882
}

0 commit comments

Comments
 (0)