initial commit
This commit is contained in:
commit
48323b32b9
23 changed files with 684 additions and 0 deletions
22
src/trpc/server.ts
Normal file
22
src/trpc/server.ts
Normal file
|
@ -0,0 +1,22 @@
|
|||
import "server-only";
|
||||
|
||||
import { headers } from "next/headers";
|
||||
import { cache } from "react";
|
||||
|
||||
import { createCaller } from "~/server/api/root";
|
||||
import { createTRPCContext } from "~/server/api/trpc";
|
||||
|
||||
/**
|
||||
* This wraps the `createTRPCContext` helper and provides the required context for the tRPC API when
|
||||
* handling a tRPC call from a React Server Component.
|
||||
*/
|
||||
const createContext = cache(() => {
|
||||
const heads = new Headers(headers());
|
||||
heads.set("x-trpc-source", "rsc");
|
||||
|
||||
return createTRPCContext({
|
||||
headers: heads,
|
||||
});
|
||||
});
|
||||
|
||||
export const api = createCaller(createContext);
|
Loading…
Add table
Add a link
Reference in a new issue