Setting http headers on Page routes
Unanswered
Glen of Imaal Terrier posted this in #help-forum
Glen of Imaal TerrierOP
I have a page route ( using pages router), that calls an API endpoint with attributes of the route like uri parts ( slug ), country code etc. From the API response, I need to set a response http header with data from the response e.g. Set a Cache-Tag header with the value of article_id:<article-id from response >. Its not possible to set to set headers in page.tsx, is there a workaround of how to set a http response header in this situation.
Thanks in advance
Thanks in advance
1 Reply
@Glen of Imaal Terrier I have a page route ( using pages router), that calls an API endpoint with attributes of the route like uri parts ( slug ), country code etc. From the API response, I need to set a response http header with data from the response e.g. Set a Cache-Tag header with the value of article_id:<article-id from response >. Its not possible to set to set headers in page.tsx, is there a workaround of how to set a http response header in this situation.
Thanks in advance
Brown bear
You could potentially try using getServerSideProps and calling the api from that setting the headers.
Extract the context and use res.setHeader
Extract the context and use res.setHeader