我已经从利用express和socket.io的节点课程扩展了聊天应用程序项目。我加入了更多的路由来简化/ signup / login / logout功能。一切都在本地环境中完美运行。如果仅将mongodb URI更改为mLab沙箱链接,则该应用程序的登录路由将中断。我已经搜索了无数线程以寻求解决方案,但是这些建议都没有奏效。我是Node的新手,所以我可能只缺少一些经验丰富的开发人员显而易见的东西。
这是引发的错误:
from uncompyle6 import
以下是导致应用崩溃的POST路由:
events.js:167
throw er; // Unhandled 'error' event
^
Error [ERR_HTTP_HEADERS_SENT]: Cannot set headers after they are sent to the client
at ServerResponse.setHeader (_http_outgoing.js:470:11)
at ServerResponse.header (/Users/B/Desktop/shadow-gab/node_modules/express/lib/response.js:767:10)
at ServerResponse.send (/Users/B/Desktop/shadow-gab/node_modules/express/lib/response.js:170:12)
at User.findOne (/Users/B/Desktop/shadow-gab/server.js:128:27)
at /Users/B/Desktop/shadow-gab/node_modules/mongoose/lib/model.js:4533:16
at process.nextTick (/Users/B/Desktop/shadow-gab/node_modules/mongoose/lib/query.js:2584:28)
at process._tickCallback (internal/process/next_tick.js:61:11)
Emitted 'error' event at:
at /Users/B/Desktop/shadow-gab/node_modules/mongoose/lib/model.js:4535:13
at process.nextTick (/Users/B/Desktop/shadow-gab/node_modules/mongoose/lib/query.js:2584:28)
at process._tickCallback (internal/process/next_tick.js:61:11)
[nodemon] app crashed - waiting for file changes before starting...
对于类似问题,最常见的回答似乎是寻找您尝试对请求做出多个答复的地方,但我看不到我在哪里做。
同样,我可以简单地将db url切换到我的本地计算机,一切正常。任何方向将不胜感激
编辑:该应用在首次登录时就损坏了,但是如果我使用注销路径,然后再登录 ,则该应用将运行。仍然不确定是什么原因造成的