can it be possible set HEADERS once for all the Response in the /api/route?
Answered
Egyptian Mau posted this in #help-forum
Original message was deleted.
Answered by joulev
Yes you can use the headers() field in next.config.js or middleware for this
8 Replies
Original message was deleted
Yes you can use the headers() field in next.config.js or middleware for this
Answer
Egyptian Mau
but that will be for the page, right
@Egyptian Mau but that will be for the page, right
Nope. It is for everything
Egyptian Mau
Understood!.. can it be possible to set it directly in the
/api/route?I think headers() in config should have a way to configure setting certain headers for certain route patterns, while for middleware it is either the matcher or something like if (req.nextUrl.pathname.startsWith("/api"))
@joulev I think headers() in config should have a way to configure setting certain headers for certain route patterns, while for middleware it is either the matcher or something like if (req.nextUrl.pathname.startsWith("/api"))
Egyptian Mau
Okay!.. I am not pretty sure about how middleware works, so I guess first request will go to middleware then to API and back to middleware, right?
@Egyptian Mau Okay!.. I am not pretty sure about how middleware works, so I guess first request will go to middleware then to API and back to middleware, right?
Not sure about the “back to middleware” part because I’ve never used middleware that way, but you can test. Otherwise yes, middleware runs first then the api route is run
@joulev Not sure about the “back to middleware” part because I’ve never used middleware that way, but you can test. Otherwise yes, middleware runs first then the api route is run
Egyptian Mau
Okay!.. I am very new to this middleware part