BrycensRanch
BrycensRanchā€¢16mo ago

Using Next.JS + Fastify

My node environment is Node 18, powered by PNPM. What's wrong: I have a few requirements for my application. I don't want to use Next's API routes due to me wanting to provide a detailed open api definition to consumers automatically. Not to mention, I prefer building with Fastify. I have considered putting trpc's server on Fastify, but, I have no idea how I would drag this into my Next.JS application. Before I stumbled upon TRPC, I was planning to have an internal API for the frontend that was considered private, but, with TRPC I see there's more possiblities. I'm also planning to host the frontend and backend in different environments. For example, Frontend would be on Vercel, backend on Railway, connected via Environment Variables to point to each other. I'd love some guidance as TRPC is a lot to swallow and process what it's doing.
3 Replies
BrycensRanch
BrycensRanchā€¢16mo ago
I'd also like to add I have looked at the examples on GitHub, but they don't seem to show Fastify and Next working together, where all backend stuff like trpc's server stays where it belongs, on Fastify.
Nick
Nickā€¢16mo ago
Nothing stopping you from having a standalone or fastify hosted tRPC API. You would then just import the types as normal and set up a client as normal for the Next.js setup, worst case you just follow the React docs rather than the Next docs (best to do the client part of the Next integration I think though, you can leverage the next features fully that way) Next provides some great tools, but it is just React at the end of the day
BrycensRanch
BrycensRanchā€¢16mo ago
Wow, thanks for the swift response. I'll give it some looking into, sounds very promising šŸ§˜ā€ā™‚ļø