设置seCookie时报错Cannot set headers after they are sent to the client

来源:7-3 cookie用于登录验证

老南瓜和小橘子

2019-04-13

(node:21048) UnhandledPromiseRejectionWarning: Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:470:11)
at handleUserRouter (C:\Users\Year Li\Desktop\blog\blog-1\src\router\user.js:16:9)
at getPostData.then.postData (C:\Users\Year Li\Desktop\blog\blog-1\app.js:86:22)
at process._tickCallback (internal/process/next_tick.js:68:7)
(node:21048) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch
block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)

写回答

1回答

双越

2019-04-13

常见错误。你在 setCookie 之前,已经进行了 res 的返回操作,即 res.end ,自己去查一查代码。

0
0

Node.js+Express+Koa2+Nest.js 开发服务端

从入门到实战,一站式掌握 Node.js+Express+Koa2

4078 学习 · 2013 问题

查看课程