I think I will - the more I think about it, it would really clean up a
lot of our code.
What I was going to suggest is that, where an initializer or plugin
would normally call api.actions.addPreProcessor() to proactively inspect
every request, this option would add a new API method like
api.actions.registerPreProcessor(). It would have almost the same signature:
api.actions.registerPreProcessor(name, callback, priority) { ... }
You could then do this in an action template:
exports.action = {
name: 'myAction',
middleware: {
'my-session-checker': { priority: 100, loadSession: true,
loadUser: false }
]
};
This method would make the change backwards-compatible. Existing
middleware would simply ignore these values and use global configs. New
middleware could do both - if configured globally, they would
addPreProcessor and work that way, so they can add support for this over
time. And apps can use a mix of both types without changing anything.
I think all that's required to support this is a simple change here:
https://github.com/evantahler/actionhero/blob/decea34c1e508b60faf850751171cf3c42b27c5a/initializers/actionProcessor.js#L126
This block of code is constructing the list of middleware to run, and
has access to self.actionTemplate. All it needs is a few lines of code
to add the additional preprocessors listed in the actionTemplate. If you
think that isn't a hare-brained idea, I'll send the PR tonight.
Thanks,
Chad