admin管理员组文章数量:1287817
I tried to access the request.headers
in the Next.js Middleware but the data is not showing up.
If I access something else, the data can appear. If I display headers it gets an error:
Server Error
TypeError: Cannot delete property 'Symbol(set-cookie)' of #<HeadersList2>
Code in Middleware:
export function middleware(request) {
console.log(request.credentials); // show -> same-origin
console.log(request.method); // show -> GET
console.log(request.headers); // page error
console.log(request.headers.referer); // not show / undefined
}
export const config = {
matcher: "/:path*/generate",
};
Fill in the data in the request variable:
Error when I display request.headers
:
I tried to access the request.headers
in the Next.js Middleware but the data is not showing up.
If I access something else, the data can appear. If I display headers it gets an error:
Server Error
TypeError: Cannot delete property 'Symbol(set-cookie)' of #<HeadersList2>
Code in Middleware:
export function middleware(request) {
console.log(request.credentials); // show -> same-origin
console.log(request.method); // show -> GET
console.log(request.headers); // page error
console.log(request.headers.referer); // not show / undefined
}
export const config = {
matcher: "/:path*/generate",
};
Fill in the data in the request variable:
Error when I display request.headers
:
- Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking. – Community Bot Commented Aug 20, 2022 at 8:02
1 Answer
Reset to default 11You can't access the headers
object directly inside the middleware. If you want to access a specific header you should use the get
method.
export function middleware(request) {
console.log(request.headers.get('referer')); // Will output `referer` header value
return NextResponse.next();
}
本文标签: javascriptError accessing requestheaders in Nextjs middlewareStack Overflow
版权声明:本文标题:javascript - Error accessing request.headers in Next.js middleware - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741327545a2372575.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论