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.
R
Romvnlyā€¢360d 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.
N
Nickā€¢360d 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
R
Romvnlyā€¢360d ago
Wow, thanks for the swift response. I'll give it some looking into, sounds very promising šŸ§˜ā€ā™‚ļø
More Posts
Error Handling vs Error FormattingI'm a bit confused from the docs about how I should be handling errors on the server. The Error HandNext.js body-parsing issueA thead to discuss this issue: https://github.com/trpc/trpc/issues/4243Cannot find module '@trpc/react-query/server' or its corresponding type declarations```ts import { createServerSideHelpers } from '@trpc/react-query/server' ``` This should work, righProcedure with generic input?Is there a way to define a procedure so that it takes input with type parameters, and returns outputDelete item {0: {json:{id: 12324}}}When i try to mutate/delete item with id i am geting this payload `{0: {json:{id: 12324}}}`, withouQuery function depends on a variableIn tRPC v10 accessing a specific path is really easy, but because of that I don't control the query 'useInfiniteQuery' hook disappeared after moving to TurborepoI am using Turborepo with Next.js with the following layout, originally a T3 app - `/apps/app` - `/pconvert the result to date objectsI am not sure if this is even trpcs responsibility but I would like to get my date objects as date oECONNREFUSED with TRPC call on VercelAnyone run into this before? I just deployed my app to Vercel and I run into this error when I triggInvalid ValDoes TRPC string input have a limit? https://prnt.sc/KlXlyoGrzP8P Edit: It was actually from stripis possible to combine next-minimal-starter with react-router-dom ?Hi, I'm trying to combine https://github.com/trpc/trpc/tree/main/examples/next-minimal-starter and rusing same query for entries appHow to use same query for many components? I don't want to request api for many times ;-; I can't pHow can I make a direct fetch on a router endpoint from TRPC in NextJS on client?In the documentation you can use the vanilla TRPC client like this: ``` const bilbo = await clientHow to get unwrapped errors out of proxy clientI'm using sveltekit and in order to redirect from SSR you need to throw an error: https://kit.svelt