Closed sean-hill closed 8 years ago
An annoyance I see with this setup is sharing configuration data between the two projects, such as authentication secrets and database connection strings.
I strongly advise you to take the approach you described. Only connect to database using studio services and avoid giving direct access to mongoose models (or any other framework you might be using to connect to db) to your api server. First to keep the responsabilities of each layer sane, and also because Studio lets you add plugins/middlewares to have a better control of whats going on in each call. I always use Studio-timer (Studio.plugin.timer) in my projects sending data to StatsD,for this reason i keep all business code on my services, you can also add timeouts or any other functionality provided by the plugins (or create your own).
Regarding the duplication... you can use different approachs: 1- If your project is not really big, you can keep all code in the same project and just create 2 different entrypoints. 2- Use enviroment variables 3- Creating another repository for your configs and add it as a dependency for the other 2 4- Avoid at all cost configuration on api (if possible) and keep it as just a thin layer between http calls and your services
@ericholiveira that has been very helpful. Thank you! Studio.js
FTW!
:) I'm closing it for now... if anything goes wrong, just let me know
MINDBLOWN!!!
It just worked flawlessly. Two separate processes, with the Services working in harmony. Absolutely amazing.
Thx... try restart process it still works :)
Hey @ericholiveira!
I'm taking a shot at using
studio-cluster
in my project. Let's say I have this project structureWhere
api server
andstudio services
are two seperate processes. The Studio services will be calling my Database to insert / update information. An example being:Currently I connect to my Database in the
api server
project, however when I do that, the Studio services don't have access to that connection or database models. I'm thinking about connecting to the Database in thestudio services
project and coupling the connection with the services. That way if theapi server
ever needs access to the Database, it'll have to call a service.I'd use
studio-cluster
to share the services between the two processes.What do you think about this approach?