test setup lackin
This commit is contained in:
13
src/app/_trpc/GetBaseUrl.ts
Normal file
13
src/app/_trpc/GetBaseUrl.ts
Normal file
@@ -0,0 +1,13 @@
|
||||
export default function getBaseUrl() {
|
||||
if (typeof window !== 'undefined')
|
||||
// browser should use relative path
|
||||
return '';
|
||||
if (process.env.VERCEL_URL)
|
||||
// reference for vercel.com
|
||||
return `https://${process.env.VERCEL_URL}`;
|
||||
if (process.env.RENDER_INTERNAL_HOSTNAME)
|
||||
// reference for render.com
|
||||
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
|
||||
// assume localhost
|
||||
return `http://localhost:${process.env.PORT ?? 3000}`;
|
||||
}
|
||||
@@ -4,21 +4,7 @@ import { ReactQueryStreamedHydration } from '@tanstack/react-query-next-experime
|
||||
import { httpBatchLink } from "@trpc/client";
|
||||
import React, { useState } from "react"
|
||||
import { trpc } from "./Client";
|
||||
|
||||
function getBaseUrl() {
|
||||
if (typeof window !== 'undefined')
|
||||
// browser should use relative path
|
||||
return '';
|
||||
if (process.env.VERCEL_URL)
|
||||
// reference for vercel.com
|
||||
return `https://${process.env.VERCEL_URL}`;
|
||||
if (process.env.RENDER_INTERNAL_HOSTNAME)
|
||||
// reference for render.com
|
||||
return `http://${process.env.RENDER_INTERNAL_HOSTNAME}:${process.env.PORT}`;
|
||||
// assume localhost
|
||||
return `http://localhost:${process.env.PORT ?? 3000}`;
|
||||
}
|
||||
|
||||
import getBaseUrl from "~/app/_trpc/GetBaseUrl";
|
||||
let clientQueryClient: QueryClient | undefined = undefined;
|
||||
const makeQueryClient = () => new QueryClient({
|
||||
defaultOptions: {
|
||||
@@ -38,12 +24,15 @@ function getQueryClient() {
|
||||
}
|
||||
}
|
||||
export default function TrpcProvider({ children }: { children: React.ReactNode }) {
|
||||
console.log("provider calls get base url")
|
||||
const baseUrl = getBaseUrl()
|
||||
console.log("provider got baseurl:", baseUrl)
|
||||
const queryClient = getQueryClient();
|
||||
const [trpcClient] = useState(() => {
|
||||
return trpc.createClient({
|
||||
links: [
|
||||
httpBatchLink({
|
||||
url: `${getBaseUrl()}/api/trpc`,
|
||||
url: `${baseUrl}/api/trpc`,
|
||||
}),
|
||||
],
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user