初學nodejs,在了不起的NodeJS有這樣一段代碼,通過中間件,實現代碼請求時間過長的控制臺打印//request-time.jsmodule.exports = function(opts){ var time = opts.time||100; return function(req,res,next){ var timer = setTimeout(function(){ console.log(req.method + " , " + req.url + " , too long!"); },time); var end = res.end; res.end = function(chunk,encoding){ res.end = end; // res.end(chunk,encoding); //直接end(chunk,encoding)會出錯 clearTimeout(timer); }; next(); }}注釋的部分就是本人的疑問,猜測是end里有this的一些東西,不知道理解對不對
NodeJS connect模塊use的問題
慕碼人2483693
2018-11-16 16:14:07