Server Side Calls with trpc app directory

I'm trying to expose a trpc route to call it with fetch, but I'm obviously doing something wrong. previously we could
const ctx = await createTRPCContext({ req, res });
const caller = appRouter.createCaller(ctx);
const ctx = await createTRPCContext({ req, res });
const caller = appRouter.createCaller(ctx);
but since the app directory release createTRPCContext uses NextRequest. has anyone been able to expose a trpc router in a nextjs api route?
1 Reply
Max
Max13mo ago
I do
export const APIClient = createTRPCReact<AppRouter>({});
export const APIClient = createTRPCReact<AppRouter>({});
then
const ctx = APIClient.useContext();
const ctx = APIClient.useContext();
then something like
const lists = await ctx.list.getLists.fetch();
const lists = await ctx.list.getLists.fetch();
Don't think this is exactly what you're looking for, but maybe? If ya can provide more information and perhaps a repo I can take a look tm.
Want results from more Discord servers?
Add your server