Param missing in put/delete
Since 4.3 values of req.params that are populated by app.param are missing in put and delete routes but not in gets.
app.param("foo", function(req, res, next, id){
orm.find(id)
.success(function(Foo){
req.params.Foo = Foo;
next();
});
});
//THIS WORKS
app.get("/foos/:foo", function(req, res, next){
res.send(req.params.Foo);
});
//THIS FAILS
app.put("/foos/:foo", function(req, res, next){
req.params.Foo.update(somethingnew);
});
I can't replicate this in a simple test case, it may be due to this being in a mounted app.
Why can you not do req.params.foo = Foo? Specifically the issue you are encountering is from adding new properties to req.params that were not defined in your route URL.
We could, or place it on directly on the req object, but either would require a time-consuming refactor of code that was working without problems until 4.2. If modifying req.params in this manner is officially deprecated then we'll undertake that task but if it's a simple fix to maintain the previously supported behavior that's obviously preferable.
I'll look into it, but yes, generally req.params is not supposed to be a "bag-o-things". Basically to make it work, I'll have to revert all the way to the old behavior where your orm.find(id) will be invoked over and over for every route, rather than only once. The reason this changed was so the pattern like you are doing will not cause multiple database lookups for the same thing in the same request.
Another simple solution you can do to sort of keep using req.params is to use .route():
app.param("foo", function(req, res, next, id){
orm.find(id)
.success(function(Foo){
req.params.Foo = Foo;
next();
});
});
app.route("/foos/:foo")
.get(function(req, res, next){
res.send(req.params.Foo);
})
.put(function(req, res, next){
req.params.Foo.update(somethingnew);
})
You should be putting Foo on the req object and not req.params. req is more the grab bag of things.