Setting cookies without middleware
Answered
Cape lion posted this in #help-forum
Cape lionOP
Considering Middleware is vendor-locked onto Vercel's edge network at the moment, is there no other way to set cookies when using RSC?
I would like for the user's cookies to be updated when their session is checked, as it may be renewed or need to be removed from their browser. There has to be a way to do this without Middleware, as we are not hosting on vercel's infrastructure.
I would like for the user's cookies to be updated when their session is checked, as it may be renewed or need to be removed from their browser. There has to be a way to do this without Middleware, as we are not hosting on vercel's infrastructure.
25 Replies
Cape lionOP
Is there some trick I can do with route handlers to make it work?
Cape lionOP
or wait, the middleware is working fine in my
standalone deployment, wtf am I not understandingMiddleware was never vender locked in lol @Cape lion
Answer
Whoever told you that, slap em a bunch
Cape lionOP
yeah, I just realised this, the documentation confused the fuck outta me too
it says it's limited to the edge runtime, which in my brain was limited to vercel
but clearly not
The edge runtime on vercel is like nodejs but with limited features
Tldr
So serverless has an issue called cold start, where when a request is made a new node js box has to startup and handle your request
So serverless has an issue called cold start, where when a request is made a new node js box has to startup and handle your request
So to counter this, nextjs has an edge runtime which is nodejs but much smaller with limited features
You can run this anywhere
The edge runtime is diff from the edge network
Edge network is vercel specific to help with getting your files to users faster
Makes sense?
Cape lionOP
yeah, that makes sense. in standalone mode, how does middleware work then? is it using that same limited runtime?
@Cape lion yeah, that makes sense. in standalone mode, how does middleware work then? is it using that same limited runtime?
Yea, so our company runs our nextjs websites on a nodejs vps, and yes it's the same as vercel
For you it dosent matter to run on the edge runtime, other than the middleware you can set the other things which use the edge runtime to use the nodejs runtime
@Arinji Yea, so our company runs our nextjs websites on a nodejs vps, and yes it's the same as vercel
Cape lionOP
ahh okay, that makes sense. it's a bummer that you can't just run on nodejs when in standalone, but at least it's there!
i should be able to get what i need working then, thanks for clearing that up and sorry for my naivety :)
i should be able to get what i need working then, thanks for clearing that up and sorry for my naivety :)
Middleware can only and only use the edge runtime, it's built like that
Np, it's a common thing even I had issues with, mark a solution if it helped
Original message was deleted
Like this
@Arinji Yea, so our company runs our nextjs websites on a nodejs vps, and yes it's the same as vercel
Cape lionOP
do you have to use something like vercel/postgres in order to use postgres on the edge? :/
we want to run our own database, and it looks like there's issues with using
pg on the edge runtime