bleupen / halacious

a better HAL processor for Hapi
MIT License
108 stars 22 forks source link

Use of apiServerLabel and server selection - halacious doesn't work with multiple connections #115

Open irothschild opened 4 years ago

irothschild commented 4 years ago

There is a problem when using the halacious plugin on a server configured with multiple connections.

  1. internals.route call to server.lookup() fails because it is not allowed on multiple connections. I'm not sure of other use cases but for me, my public API is specified with the apiServerLabel option (which are the links I want to present, no matter which connection I receive a request on) so I have changed the call to selection.lookup().

  2. I'm not sure of the reason for selection.ext('onPostHandler', internals.postHandler); using selection and not server. The plugin server.register() call already has an option to select which connections the plugin should apply to so using selection here seems like an error or redundancy at best. I have changed it to server.ext('onPostHandler', internals.postHandler); which allows me to use halacious on multiple connections but lookup routes on the canonical apiServerLabel connection.

These changes are in https://github.com/Clarify/halacious/tree/use-apiServerLabel-for-route-lookup If it seems useful, I can make a PR.