balderdashy / sails-hook-subapps

Sails hook for including child Sails apps into a parent app
18 stars 3 forks source link

status? #4

Closed tjwebb closed 8 years ago

tjwebb commented 9 years ago

Hey @sgress454 @mikermcneil can you offer a taste of what plans there are for this module?

sgress454 commented 9 years ago

A wonderful question. I'll take a look at this ol' beauty and see if she still runs. If so, then it really just needs to some docs.

tjwebb commented 9 years ago

Cool, thanks.

tjwebb commented 8 years ago

Apparently not.

kevinob11 commented 8 years ago

Anything here? This was suggested (here balderdashy/sails#2083) as the way to handle sails modules, is that still the case, is there documentation coming?

sgress454 commented 8 years ago

@kevinob11 well, yes and no. Clearly I intended to spend some time on this and got sidetracked. The idea behind it is sound; that is, I still think that the best way to leverage whole Sails apps as plugins is to load them using a hook like this one. Whether or not this specific hook actually does the trick is another story.

It certainly got at least partway there. You can lift the app in the "example" folder, go to /blog and see the subapp's homepage (I just pushed a change to make this more clear), go to /user and /blog/user to see the "user" model which is shared from the parent to the subapp, and go to /blog/post to see the "post" model which is solely the product of the subapp. You can look at example/config/subapps.js to see how the models are tied together. So, routing in the subapp works, and some rudimentary model sharing, but not sure about much else. What I really wanted to show as an example was something you could plug in to a Sails app to provide an admin panel for the app's models, a kind of phpMyAdmin for Sails, but I only got a few steps in before being pulled away.

So depending on what you're looking for, this hook may work just fine for you. The biggest things to remember when developing a subapp are 1) you won't have globals, so always use sails.models instead of global model names, and this.sails (or req._sails in controller actions) to refer to the Sails instances, and 2) you can access the parent app inside of subapp module code (controllers, services, models, etc.) as this.sails.parentApp.

All in all I'd love to get this hook to be more robust, add a better example and some docs. Maybe I'll make it a holiday project. If you end up using it and would like to contribute, please feel free!

kevinob11 commented 8 years ago

I'm testing this https://github.com/leeroybrun/sails-util-mvcsloader/tree/master/libs right now, in general I prefer the idea of it to nesting a full sails app, but I'll try to post back here when I know more.