2016-02-21 58 views
0

下面是使用快遞框架和反手有火力API我的服務器後快遞和火力地堡不能設置頁眉他們被送到

我有兩個問題,即怎麼來的我的函數獲取調用兩次,什麼是錯誤

app.get('/user/:userID/profile/edit', function(req, res) { 
    var authData = ref.getAuth(); 
    var str = (req.query.message == undefined ? "" : req.query.message); 
    if(authData) { 
    if(req.params.userID == authData.uid){ 
     ref.child("users").child(authData.uid).on("value",function(snapshot) { 
     var userData = snapshot.val(); 
     res.render('Profile/edit', { 
      title : "Price Drop Alert", 
      pagetitle : "Profile", 
      firstname : userData.firstname, 
      lastname : userData.lastname, 
      dob : userData.dob, 
      tel : userData.tel, 
      email : userData.email, 
      uid : authData.uid, 
      message : str 
     }); 
     }); 
    } 
    else 
     res.sendStatus(404); 
    } 
    else 
    res.redirect('/?message='+encodeURIComponent("User is not logged in")); 
}); 

app.post('/user/:userID/profile/edit', function(req,res) { 
    var uid = req.params.userID; 
    if(req.body.fsubmit == "Submit"){ 
    ref.child("users").child(uid).update({ 
     firstname : req.body.fname 
    }); 
    console.log("update"); 
    res.redirect('/user/'+req.params.userID+"/profile/edit"); 
    } 
}); 

下面是錯誤,我得到

update 
Error: Can't set headers after they are sent. 
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:346:11) 
    at ServerResponse.header (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/response.js:718:10) 
    at ServerResponse.send (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/response.js:163:12) 
    at done (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/response.js:957:10) 
    at View.exports.renderFile [as engine] (/home/saunish/WebstormProjects/priceDrop/node_modules/ejs/lib/ejs.js:355:10) 
    at View.render (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/view.js:126:8) 
    at tryRender (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/application.js:639:10) 
    at EventEmitter.render (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/application.js:591:3) 
    at ServerResponse.render (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/response.js:961:7) 
    at /home/saunish/WebstormProjects/priceDrop/app.js:130:13 
Error: Can't set headers after they are sent. 
    at ServerResponse.OutgoingMessage.setHeader (_http_outgoing.js:346:11) 
    at ServerResponse.header (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/response.js:718:10) 
    at ServerResponse.send (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/response.js:163:12) 
    at done (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/response.js:957:10) 
    at View.exports.renderFile [as engine] (/home/saunish/WebstormProjects/priceDrop/node_modules/ejs/lib/ejs.js:355:10) 
    at View.render (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/view.js:126:8) 
    at tryRender (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/application.js:639:10) 
    at EventEmitter.render (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/application.js:591:3) 
    at ServerResponse.render (/home/saunish/WebstormProjects/priceDrop/node_modules/express/lib/response.js:961:7) 
    at /home/saunish/WebstormProjects/priceDrop/app.js:168:13 
+0

同樣的問題(還沒有答案):http://stackoverflow.com/questions/35507201/firebase-warning-exception-was-thrown-by-user-callback-error -cant-set-header –

+0

需要使用Express服務器來代理Firebase調用? –

回答

1

您需要更改)一次()方法(否則你的回調函數被觸發過y時間有更新到您的數據,