tRPCttRPC
Powered by
RuleR
tRPC•15mo 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
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;
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
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";
  }),
});
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";
  }),
});
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

is it possible to use trpc on next js api routes
kumard3Kkumard3 / ❓-help
3y ago
Using tRPC in Next.js Middleware
FinnFFinn / ❓-help
3y ago
tRPC in Next without api rotes
MadaShindeInaiMMadaShindeInai / ❓-help
3y ago
Next.js + tRPC, multitenancy, access Next.js Router when setting tRPC headers
anton.johanssonAanton.johansson / ❓-help
3y ago