I'm trying to resolve a specific requirement for our web app. We have a page 'Item' that in case of an item sold out should keep showing item but the page's response code must be set to 404. I'm trying something like that:
in pages/[id]/Item.tsx:
static async getInitialProps(ctx) {
//retrieve item
if (item.isSoldOut) {
ctx.res.statusCode = 404;
}
//all other stuff
}
but it will automatically redirect to the homepage with status code 302. How to achieve this behavior?