I am working on a middleware that needs bodyParser
to run, but I don't want to make the app bring that in as a dependency. Instead, I want to make a package that requires that and exports a middleware like this:
//routes.js
app.use('/', middlewareWrapper(thing));
//middlware.js
export function middlewareWrapper(thing) {
return function addBody(req, res, next) {
function othermiddleware(_req, _res) {
// do something with thing and _req
return next();
}
return bodyParser.json()(req, res, othermiddleware);
};
}
This looks like it would work, and the othermiddleware
is called, but with no arguments.
I found another answer that addresses this in basically the same way (it's old, but JS still works the same way): https://stackoverflow.com/a/17997640/444871
Why is the othermiddleware
being called with no args?