3 ms·
Nodal supports Middleware for post-processing controller output (gzip, etc.) and I could do something similar for pre-processing but right now it's just encoura
by keithwhor 11y ago
Nodal supports Middleware for post-processing controller output (gzip, etc.) and I could do something similar for pre-processing but right now it's just encouraged that you write your own intermediate controller, get all controllers to inherit from it and do something like a super call. Will think about what pre-processing middleware would look like / be called.
- pfooti 11y agoYah, I had thought about inheritance and super, but without multiple inheritance, it'd be tricky. Basically a lot of my routes do stuff like parameter validation (I store specific criteria on the model class, but apply them in the route), creating a new object from validated post params, loading from the database, storing to the database, authorizing and authenticating, etc. Then my route definition declares the per route middleware and the specific controller only has to encapsulate route specific business logic. I could do that just by putting it all in a utils package and calling loadItem(), validate params() etc at the top of each handler, but that feels less elegant. It may be that I've just been using hapi.js for too long, the modularity and composition in that framewrok.is quite elegant, IMO.