hapi icon indicating copy to clipboard operation
hapi copied to clipboard

Support for plugin.inject

Open petermilan opened this issue 12 years ago • 6 comments

Could we add also functionality to be able to inject another requests from the plugin? for now there exists a method server.inject which could be also used for: " invoking routing logic internally". This is possible to perform from the server, but not from the plugin. Only one workaround to achieve this is:

plugin.servers.forEach(function(server) {
  server.inject('/test-path', function(res) {
    reply(res.result);
  });
});

but there must be just one instance of server (usning Hapi.createServer())

petermilan avatar Apr 30 '14 11:04 petermilan

Not sure we can do this. The whole point of the pack is to abstract how many servers are inside of it. Which server should we inject into?

hueniverse avatar Apr 30 '14 18:04 hueniverse

I was hoping that it could be the same server as the server.route is called? The method server.route (plugin.route) is also called for each server?

petermilan avatar May 01 '14 14:05 petermilan

There is a big difference. How do you expect this function to collect/consolidate the responses? what if the endpoint was only added to a few of the servers?

hueniverse avatar May 01 '14 14:05 hueniverse

Hmm I am not sure. If you think, that this could not be achieved, I agree with you. I just thought that if there is a plugin.route function, there could be a possibility to do also plugin.inject. Because in my example code- the foreach is really dangerous, and I also don't know how to identify correct server (in my case there should be just one- but I can not rely on that). Maybe the only one good approach here is to pass desired server to the plugin using the plugin options.

petermilan avatar May 01 '14 14:05 petermilan

I don't see how this can work.

hueniverse avatar May 01 '14 15:05 hueniverse

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

lock[bot] avatar Jan 09 '20 04:01 lock[bot]