diff --git a/apps/trpc-app/src/trpc-client.ts b/apps/trpc-app/src/trpc-client.ts index 4065388b9..0c68031fd 100644 --- a/apps/trpc-app/src/trpc-client.ts +++ b/apps/trpc-app/src/trpc-client.ts @@ -5,7 +5,7 @@ import superjson from 'superjson'; export const { provideTrpcClient, TrpcClient, TrpcHeaders } = createTrpcClient({ - url: 'http://localhost:4205/api/trpc', + url: '/api/trpc', options: { transformer: superjson, }, diff --git a/package.json b/package.json index 3d09b3b81..20d96fb67 100644 --- a/package.json +++ b/package.json @@ -8,8 +8,8 @@ "preinstall": "npx only-allow pnpm", "prepare": "git config core.hookspath .githooks", "start": "nx serve", - "build": "nx run-many --target build --all --parallel=1 --exclude=trpc-app", - "e2e": "nx run-many --target e2e --all --parallel=1 --exclude analog-app-e2e-playwright,trpc-app-e2e-playwright", + "build": "nx run-many --target build --all --parallel=1", + "e2e": "nx run-many --target e2e --all --parallel=1 --exclude analog-app-e2e-playwright", "test": "nx run-many --target test --all", "build:vite-ci": "npm run build", "test:vite-ci": "nx run-many --target test --all", diff --git a/packages/nx-plugin/src/generators/app/files/trpc/src/trpc-client.ts__template__ b/packages/nx-plugin/src/generators/app/files/trpc/src/trpc-client.ts__template__ index 088ff11ce..72e4952b0 100644 --- a/packages/nx-plugin/src/generators/app/files/trpc/src/trpc-client.ts__template__ +++ b/packages/nx-plugin/src/generators/app/files/trpc/src/trpc-client.ts__template__ @@ -3,7 +3,7 @@ import { createTrpcClient } from '@analogjs/trpc'; import { inject } from '@angular/core'; export const { provideTrpcClient, TrpcClient } = createTrpcClient({ - url: 'http://127.0.0.1:4200/api/trpc', + url: '/api/trpc', }); export function injectTrpcClient() { diff --git a/packages/trpc/src/lib/client/client.ts b/packages/trpc/src/lib/client/client.ts index ae46b0db8..117ae82aa 100644 --- a/packages/trpc/src/lib/client/client.ts +++ b/packages/trpc/src/lib/client/client.ts @@ -11,6 +11,7 @@ import { import { createTRPCRxJSProxyClient } from './trpc-rxjs-proxy'; import { CreateTRPCClientOptions } from '@trpc/client/src/createTRPCUntypedClient'; import { HTTPHeaders } from '@trpc/client/src/links/types'; +import { FetchEsque } from '@trpc/client/dist/internals/types'; export type TrpcOptions = { url: string; @@ -25,6 +26,25 @@ const tRPC_INJECTION_TOKEN = new InjectionToken( '@analogjs/trpc proxy client' ); +function customFetch( + input: RequestInfo | URL, + init?: RequestInit & { method: 'GET' } +) { + if ((globalThis as any).$fetch) { + return (globalThis as any).$fetch + .raw(input.toString(), init) + .catch((e: any) => { + throw e; + }) + .then((response: any) => ({ + ...response, + headers: response.headers, + json: () => Promise.resolve(response._data), + })); + } + return fetch(input, init); +} + export const createTrpcClient = ({ url, options, @@ -49,6 +69,7 @@ export const createTrpcClient = ({ headers() { return TrpcHeaders(); }, + fetch: customFetch as FetchEsque, url: url ?? '', }), ],