-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Combine submission middlewares into controllers #149
Comments
|
@karrui @tshuli i had a discussion with @mantariksh today, and we thought that instead of chaining middlewares, we can group relevant parts of the For example, instead of doing this: app.route(...).post(
celebrate({
body: Joi.object({
valueA: Joi.string(),
valueB: Joi.boolean()
})
})
middlewareUsingValueA, // naked middleware function with implicit
middlewareUsingValueB, // dependency on upstream middleware for protection
) We can do this instead: // Exported together so that it's not possible to
// use middleware without protection
export const middlewareUsingValueA = [
celebrate({
body: Joi.object({
valueA: Joi.string(),
})
}),
(req, res, next) => {...} // or implemented as a separate function
]
export const middlewareUsingValueB = [
celebrate({
body: Joi.object({
valueB: Joi.string(),
})
}),
(req, res, next) => {...}
]
app.route(...).post(
middlewareUsingValueA,
middlewareUsingValueB
) |
@frankchn could we get your help with merging the middlewares for the encrypt mode submission API Happy to discuss further if necessary! |
Note: to also refactor associated routes for
|
Blocked by #144
Many of our middleware functions are being chained together and used as services, which is an anti-pattern. This causes problems such as having long-range object and type dependencies, which must be overridden by the developer with type assertions.
A better solution where possible, is to merge middlewares into a single controller function as far as possible so that dependencies are clearly defined.
The text was updated successfully, but these errors were encountered: