tRPCttRPC
Powered by
TeixeiraT
tRPC•13mo ago•
3 replies
Teixeira

Route not found when using Fastify adapter

I'm currently running into the following error when attempting to issue a request to my server which is leveraging Fastify:
[19:04:02.888] INFO (57024): Route POST:/associateSocialMediaAccount not found
    reqId: "req-1"
[19:04:02.892] INFO (57024): request completed
    reqId: "req-1"
    res: {
      "statusCode": 404
    }
    responseTime: 5.059000000357628
[19:04:02.888] INFO (57024): Route POST:/associateSocialMediaAccount not found
    reqId: "req-1"
[19:04:02.892] INFO (57024): request completed
    reqId: "req-1"
    res: {
      "statusCode": 404
    }
    responseTime: 5.059000000357628


I'm instantiating the server as such:
const fastifyServer = fastify({
    logger: true,
    maxParamLength: 5000
});

fastifyServer.register(fastifyTRPCPlugin, {
    prefix: '/trpc',
    trpcOptions: {
        router: appRouter,
        createContext,
        onError({ path, error }) {
            logger.error(`Error in tRPC handler on path '${path}':`, error);
        }
    } satisfies FastifyTRPCPluginOptions<AppRouter>['trpcOptions']
});

try {
    await fastifyServer.listen({
        port: environment.API_PORT,
        host: environment.isDev ? 'localhost' : '0.0.0.0'
    });
} catch (reason: unknown) {
    logger.error(reason);
}
const fastifyServer = fastify({
    logger: true,
    maxParamLength: 5000
});

fastifyServer.register(fastifyTRPCPlugin, {
    prefix: '/trpc',
    trpcOptions: {
        router: appRouter,
        createContext,
        onError({ path, error }) {
            logger.error(`Error in tRPC handler on path '${path}':`, error);
        }
    } satisfies FastifyTRPCPluginOptions<AppRouter>['trpcOptions']
});

try {
    await fastifyServer.listen({
        port: environment.API_PORT,
        host: environment.isDev ? 'localhost' : '0.0.0.0'
    });
} catch (reason: unknown) {
    logger.error(reason);
}


appRouter
appRouter
looks like this:
(...)
import associateSocialMediaAccount from './procedures/associateSocialMediaAccount.js';

export const appRouter = router({
    associateSocialMediaAccount
});
(...)
import associateSocialMediaAccount from './procedures/associateSocialMediaAccount.js';

export const appRouter = router({
    associateSocialMediaAccount
});


associateSocialMediaAccount.ts:
associateSocialMediaAccount.ts:

export default publicProcedure
    .input(socialMediaAccountSchema)
    .mutation(async (opts) => {
        // ...
    });
export default publicProcedure
    .input(socialMediaAccountSchema)
    .mutation(async (opts) => {
        // ...
    });


I have triple checked that the client and server versions of tRPC match (
^11.0.0-rc.700
^11.0.0-rc.700
), I'm on
"typescript": "^5.7.3"
"typescript": "^5.7.3"
on both server and client, Node version
v22.11.0
v22.11.0
Solution
The client side
url
url
was missing the
/trpc
/trpc
prefix set in the server.
Jump to solution
tRPCJoin
Move Fast & Break Nothing. End-to-end typesafe APIs made easy.
5,015Members
Resources
Recent Announcements

Similar Threads

Was this page helpful?

Similar Threads

Throwing fastify errors when using fastify adapter
rdRrd / ❓-help
3y ago
SSG on nextJS when appRouter is made with fastify adapter?
DelvisDDelvis / ❓-help
4y ago
Using Next.JS + Fastify
BrycensRanchBBrycensRanch / ❓-help
3y ago