繁体   English   中英

Next.js中的getServerSideProps如何添加header

[英]How to add header to getServerSideProps in Next.js

我想通过 Next.js 中的 getServersideProps 传递 JWT 访问令牌。令牌存储在本地存储中。 有什么办法吗?

想要在 Next.js 的 getServerSideProps 中添加 headers

getServerSideProps接受一个context参数,该参数包括用于访问IncomingMessage ( req ) 和ServerResponse (res ) 对象的键。 如果要添加一个header,可以使用response对象的setHeader方法。

export function getServerSideProps(context) {
  // print incoming headers
  console.log(context.req.headers);

  // add header
  context.res.setHeader("X-Foo", "Bar");

  return {
    props: {},
  };
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM