Matan NahmaniM
tRPC3y ago
1 reply
Matan Nahmani

calling TRPCProxyClient from inside trpc procedure fails on vercel route handlers edge runtime

i setup my client as following:
export const serverToServerApi = createTRPCProxyClient<AppRouter>({
  transformer,
  links: [
    httpLink({
      url: getUrl(),
      fetch: async (input, init) => {
        console.log("fetch", input, init);
        const res = await fetch(input, init);
        console.log("RES", res);
        return fetch(input, init);
      },
      headers() {
        return {
          "x-trpc-source": "server",
          Authorization: `Bearer ${env.SERVER_API_KEY}`,
        };
      },
    }),
  ],
});

and then inside a trpc procedure i'm trying to call it as following:
        void serverToServerApi.ai.newMembers.mutate({
          roomId: room.id,
          preferenceIds: [insertResult[0].id],
        });

this result in request always failing with an error of:
TRPCClientError: Unexpected end of JSON input

any ideas how to solve this?
Was this page helpful?