Open desmondmorris opened 9 years ago
Some sort of middleware stack might be best here. Keeping in mind that overriding might not be the goal, but extending/hooking might sometimes be more beneficial.
@joshuajabbour I think you are right - middleware is probably the way to go - should be trivial to implement pre/post style hooks here.
My question is, after res.end
is executed, can a middleware hook be executed after?
No, res.end
/res.send
is the end of it all. I looked into this a bit last night, and the consensus seems to be wrapping send
. This however is I think a conceptual flaw with middleware that we'll have to work around. What we really want it to have a result object that can be passed through middleware, maybe pushing that onto the response
object is the only way to go...
Hmm maybe the default handlers become something like this?
(req, res, next ) => {
if (typeof next === 'function') {
return next(req, res);
}
// DEFAULT HANDLER LOGIC
}
Though I think "next" is always a function, so this may be flawed.
There should be a way to override the default generated handlers. You should be able to house the resource files in a directory that is discoverable or configurable.