Splitting Next.js API endpoints into separate Vercel functions #455
dangreaves
started this conversation in
General
Replies: 1 comment 3 replies
-
Hey @dangreaves, thanks for opening the discussion! No, I haven't considered in depth, but my thinking of benefits with one global handler is that:
I very much doubt that composition of the endpoints will have any significant added cold start time, but haven't tested it thoroughly! That said, it could be possible to expose your sub-routers as individual functions pretty easily but by jumping through some hoops. Haven't tested, but below should work
|
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hey @KATT - love the approach you have taken with this. Proper type sharing in Next.js projects is something I have been trying to achieve for a while and your solution here ticks all the boxes.
One thing which I would like hear your thoughts on is whether or not this will ever be able to split endpoints into their own Next.js API functions, rather than one giant
[trpc]
function. The reason for this is that when deploying to serverless providers like Vercel, they split up each API file into it's own Lambda function.This has the benefit of keeping the weight of each function low which significantly reduces cold start times, because only the code necessary for that particular endpoint is included in the function.
I'm concerned that as my project grows, the
[trpc]
function will gradually get bigger and bigger, until I end up having some ops issues with the Lambda execution.Is this something which you have considered? Would love to hear your thoughts.
Beta Was this translation helpful? Give feedback.
All reactions