I am currently setting up routes for an express router in my project. I have a validator that deals with promises, requiring me to use await in the code. Here is how it looks:
constructor() {
this.router = express.Router();
this.router.use(express.json());
this.router.use(express.text({ type: ['text/plain', 'text/html'] }));
}
async addCreateTaskRoute(validator, handler) {
if (!handler) {
throw Error('cannot add empty handler');
}
this.router.post('/tasks', await validator, handler);
return this;
}
Do you think this solution is appropriate? Are there any alternatives? The context of this coding snippet is within a middleware of the project, where the validator and handlers are sourced from external modules and are of type express RequestHandler.