好吧,我的问题是我想将一些变量从第一个中间件传递给另一个中间件,我尝试这样做,但是有req.somevariable
一个“给定为'undefined'”。
//app.js
..
app.get('/someurl/', middleware1, middleware2)
...
////middleware1
...
some conditions
...
res.somevariable = variable1;
next();
...
////middleware2
...
some conditions
...
variable = req.somevariable;
...
Local variables are available in middleware via req.app.locals
expressjs.com/pt-br/api.html#app.locals
res
在Middleware1 中将值分配给了它并尝试从req
Middleware2中获取了它。