I have a REST API and many endpoints include a specific placeholder, like this:
app.get('/client/:client', getClient);
app.put('/client/:client', updateClient);
app.get('/tasks/:client', getClientTasks);
// ...
I want to run a middleware for all paths, that include the :client placeholder.
This is what I've come up with, but it does not work for me:
// My sample middleware:
function validateClient(req, res, next) {
console.log('Validate client', req.params.client);
next();
}
// I want to bind the middleware to all endpoints with ':client' in them:
app.use(':client', validateClient); // <- validateClient is not called!?
// The REST endpoints.
app.get('/client/:client', getClient);
app.put('/client/:client', updateClient);
app.get('/tasks/:client', getClientTasks);