I don't understand why this works:
instance.use(restify.bodyParser());
but this doesn't work:
instance.use((req, res, next) => {
restify.bodyParser();
next();
});
UPD: I've tried to restify.bodyParser()(req, res, next)
. In fact it doesn't work for some reason.
restify.bodyParser()
exports array of functions: [read, parseBody]. So using restify.bodyParser()(...)
throws error ... is not a function
.
I'm still trying to achieve why so.
use
expects an argument of the form function (req, res, next)
or an array of functions of this form. restify.bodyParser()
is an array of functions of this form. Hence, you will need pass req
, res
, next
to each of the functions in the array. Depending on what you want to do, you might want to return an array of middlewares or call the middlewares in sequence.