在 NextJs 的 getInitialProps() 中设置缓存控制标头

Cyr*_*ker 5 javascript reactjs next.js

我需要Cache-Control在方法中使用动态值设置标头getInitialProps。我尝试了以下。

if(context.res){
    context.res.setHeader('Cache-Control','My-Cache-Control');
    context.res.setHeader('My-Header','My-Value');
}
Run Code Online (Sandbox Code Playgroud)

但看起来 NextJs 在发送响应之前覆盖了标头值。以下是cache-control浏览器中响应标头中的标头值。

Cache-Control: no-store, must-revalidate
My-Header: My-Value
Run Code Online (Sandbox Code Playgroud)

如果有什么遗漏请告诉我。

Fad*_*lam 2

正如这个github bug中提到的

使用res.setHeader()

res是 Node.js http.ServerResponse