hapijs / glue

Server composer for hapi.js
Other
245 stars 62 forks source link

`registration`: accept alternatively a function #93

Closed felixheck closed 7 years ago

felixheck commented 7 years ago

Hi there!

I'm using glue in lots of projects, it's quite nice. Well done 😉 But manifest.registrations accepts currently an array of objects and options.preRegister is a callback function w/ the signature function(server, next).

I would like to use alternatively a function instead of the array of objects. The signature could be function(server) and the return value is again an array of objects.

Currently I'm using a few hapi plugins which decorate server and I would like to use these methods within the registration of further plugins. So for the moment I register those plugins in manifest.registrations and register the further plugins within the glue.compose callback. It is not really smart. My aim is that all the registrations are managed by glue.

What do you think about this API change/extension? 😄 Thanks so far.

Cheers!

csrl commented 7 years ago

I guess you mean that one plugin is dependent on another? So you want to control the load order? Glue registers the plugins by the registrations array order. Beyond that you'll want to manage your plugin dependencies - https://github.com/hapijs/glue/blob/master/API.md#notes

felixheck commented 7 years ago

Yeah but the dependency is not really a dependency. It is possible to use the plugins without the other one.

Use Case: Plugin A is a plugin without a decorator. It just run some code in the background. Plugin B is plugin decoration the server object.

It is possible to use A without B but the usage gets simplified with B. So even when I load B before A it does not help because I could not access the decorated server object within the registrations.

csrl commented 7 years ago

I guess I am not yet understanding. Each plugin registration function has access to the server object. Are you saying that when Plugin B is registered first and it decorates the server object, that then when Plugin A is registered second, the server object passed to Plugin A is not decorated?

felixheck commented 7 years ago

Yeah but I need the decorated server object within the glueregistration process, because I need it for some options of the second registration..

felixheck commented 7 years ago

I'll prepare a minimal working example tomorrow :)

csrl commented 7 years ago

Any update here? If you can create a simple example without using glue (just directly calling server.register) that shows how the first plugin decorates the server object, but the decoration does not show up in the 2nd plugin's server object, then I suggest opening an issue on the hapi project to find out if that is expected or not. This seems out of scope for glue to care about.

felixheck commented 7 years ago

It does not matter anymore. Contributed to one of the plugins to solve this issues. It a workaround but i think the only solution. Nevertheless: thanks!

lock[bot] commented 4 years ago

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.