将标题发送到客户端哨兵后无法设置标题
我在此代码上从sentry.io那里遇到了一个错误,我告诉我,我无法在之后设置标题 他们被发送给客户。 这是下一个JS应用
export async function getServerSideProps(ctx) {
const { res } = ctx
res.setHeader('Content-Type', 'text/plain')
res.write('User-agent: *\n')
res.write('Disallow: \n')
res.write('Sitemap: https://kalla.com/sitemap.xml\n')
res.end()
return {}
}
const Robots = () => null
export default Robots
I get an error from sentry.io on this code, i's tell me that I can't set headers after
they are sent to the client.
It's a next js app
export async function getServerSideProps(ctx) {
const { res } = ctx
res.setHeader('Content-Type', 'text/plain')
res.write('User-agent: *\n')
res.write('Disallow: \n')
res.write('Sitemap: https://kalla.com/sitemap.xml\n')
res.end()
return {}
}
const Robots = () => null
export default Robots
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
响应标头仅通过请求发送一次,如果您尝试将其设置并再次发送,则会出现错误。
writehead()可以与setheader()合并,但是writehead()优先于后者。
writehead()acepts以下args:writehead(statuscode,statusmessage,标题),但是接受setheader(键,值)。
Response header is only sent once with a request, and if you try to set it and send it again you will get an error.
writeHead() can be merged with setHeader(), but the writeHead() has precedence over the latter.
WriteHead() acepts these args :writeHead(statusCode, statusMessage, headers), however accepts setHeader(key, value).