Nodejs as runtime for middleware
Unanswered
Labrador Duck posted this in #help-forum
Labrador DuckOP
It's quite frustating that the nextjs doesn't provide an option to choose runtime for middlewares. I could sense the motivation for keeping it lightweight and making it fast but still I think option should be provided.
Like I am trying to use better sqlite3, for local development and middleware for checking auth I am not able to do it... I don't want to hit the turso server for local development and schema is changing too in this early state. (edit I know I can turso in local but that's for example)
I really like the convenience of the middlewares for checking auth or for checking permissions etc...
Like I am trying to use better sqlite3, for local development and middleware for checking auth I am not able to do it... I don't want to hit the turso server for local development and schema is changing too in this early state. (edit I know I can turso in local but that's for example)
I really like the convenience of the middlewares for checking auth or for checking permissions etc...
5 Replies
Labrador DuckOP
Also this discussion has no reply from the core team since the leerob reply
https://github.com/vercel/next.js/discussions/46722
https://github.com/vercel/next.js/discussions/46722
Labrador DuckOP
Why not root layout???
Because we cannot set headers in layout functions....Let's say I have use case for adding some header value...with middleware I can easily do that
Server components can't even set cookies..so I don't think layout function would be able to set cookies
Because we cannot set headers in layout functions....Let's say I have use case for adding some header value...with middleware I can easily do that
Server components can't even set cookies..so I don't think layout function would be able to set cookies
unfortunately, it's a hard, cold truth that nodejs for middleware is not supported. a common workaround is that you make a nodejs route handler and have your middleware communicate with that route handler via fetch(). your middleware provides the relevant input and the route handler does the heavy lifting
yes that's a messy workaround and yes i agree they should support nodejs for middleware, but the vercel guys are unwilling to implement that so there is only so much you can do
Labrador DuckOP
Thanks joulev for the reply. I will try this workaround