当前位置: 首页>NodeJS>ExpressJS>Send a response from middleware

Send a response from middleware

时间:2015-07-10 12:56 来源:网络整理 作者:KKWL 点击:
That's because you're still continuing on with the execution and calling next(), which moves onto the next middleware or route in the stack. Return early to stop it from moving onto the next middleware. app.use(function(req,res,next){if(req

That's because you're still continuing on with the execution and calling next(), which moves onto the next middleware or route in the stack.

Return early to stop it from moving onto the next middleware.

app.use(function(req,res,next){ if(req.query.key === undefined) { //return out of the function here return res.send("Sorry!"); } req.db = db; next(); }); app.use('/', routes);

顶一下
(0)
0%
踩一下
(0)
0%
------分隔线----------------------------