RuleR
tRPC14mo ago
9 replies
Rule

tRPC 404 in Next.js API Routes

I'm trying to upgrade my Next.js version to 15 and still use tRPC with API route. I'm getting 404 for all trpc api routes. Is anyone else facing the same issue? All the other api routes are working fine.

app/api/trpc/[trpc]/route.ts
import { fetchRequestHandler } from "@trpc/server/adapters/fetch";

import { appRouter } from "./trpc";

const handler = async (request: Request) => {
  return await fetchRequestHandler({
    endpoint: "/api/trpc",
    req: request,
    router: appRouter,
    onError: (opts) => {
      console.error(`[${opts.error.code}] ${opts.path}:`, opts.error);
    },
  });
};

export const GET = handler;
export const POST = handler;


trpc.ts
import { initTRPC } from "@trpc/server";

const t = initTRPC.create();
export const router = t.router;
export const publicProcedure = t.procedure;
export const appRouter = router({
  hello: publicProcedure.query(async () => {
    return "world";
  }),
});
Was this page helpful?