Tengo una API REST y muchos puntos finales incluyen un marcador de posición específico, como este:
app.get('/client/:client', getClient); app.put('/client/:client', updateClient); app.get('/tasks/:client', getClientTasks); // ... Quiero ejecutar un middleware para todas las rutas, que incluyen el marcador de posición :client .
Esto es lo que se me ocurrió, pero no funciona para mí:
// 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);