0
我是新來的節點,並試圖在mongodb中創建模型。當我打電話localhost:3000/a。我看到的請求兩次在控制檯也越來越誤差不能設置頭髮送之後發送後無法設置標題。雖然調用create(data,cb)
module.exports = function(app) {
app.get('/',function(req,res){
res.render("adminpanel/panel",{});
});
app.get('/a',function (req,res,cb) {
console.log(req.url)
var User = app.models.test;
var user = app.models.test();
user.username = "admin";
user.type = "hey";
user.password = "132";
user.email = "[email protected]";
User.create(user,cb);
res.send("hey");
});
};
output:
/a
/a
Error: Can't set headers after they are sent.
at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:344:11)
at ServerResponse.header (E:\workspace\orderapp\node_modules\express \lib\response.js:718:10)
at ServerResponse.contentType (E:\workspace\orderapp\node_modules\express\lib\response.js:551:15)
at ServerResponse.send (E:\workspace\orderapp\node_modules\express\lib\response.js:138:14)
at E:\workspace\orderapp\server\boot\root.js:14:9
at Layer.handle [as handle_request] (E:\workspace\orderapp\node_modules\express\lib\router\layer.js:95:5)
at next (E:\workspace\orderapp\node_modules\express\lib\router\route.js:131:13)
at Route.dispatch (E:\workspace\orderapp\node_modules\express\lib\router\route.js:112:3)
at Layer.handle [as handle_request] (E:\workspace\orderapp\node_modules\express\lib\router\layer.js:95:5)
at E:\workspace\orderapp\node_modules\express\lib\router\index.js:277:22
錯誤:發送之後無法設置頭。意味着您嘗試多次發送該響應。你可以爲你的'cb'顯示代碼。 – Subburaj
那我想弄明白我在哪裏發送迴應第二次。第二爲什麼上面的代碼塊運行兩次? – tecx20