Looking to use the Restify conditionalHandler plugin, and I have multiple middleware in certain routes.
Looking to convert this:
server.put('/forceUpdate', middleware.requiresLogin, versionController.update);
into something like this
server.put('/addVersion', restify.plugins.conditionalHandler([
{version: '1.1.3', handler: middleware.requiresLogin, versionController.update},
{version: '2.0.1', handler: middleware.requiresLogin, versionController.update}
]));
I can't chain the middleware in the handler, is there a best practice for this?
Does handler accept an array?
My other thought adding more middleware as conditionalHandlers, but that seems excessive.
Any help would be appreciated.
Yes, you can pass an array of middleware functions according to the documentation. So your code will look like this:
server.put('/addVersion', restify.plugins.conditionalHandler([
{version: '1.1.3', handler: [middleware.requiresLogin, versionController.update]},
{version: '2.0.1', handler: [middleware.requiresLogin, versionController.update]}
]));