Allow app to be runnable with cluster - #33
Conversation
|
Since this removes the internal clustering and monitoring, it shouldn't be merged until strong-supervisor is released. To reproduce the not-startable with cluster, try something like: Or use pm2 or strong-supervisor. |
|
Test PASSed. To trigger a build add comment - ".test\W+please" |
|
Could we move The more we move out of |
👍 I would also consider renaming the function to |
|
Sure, I think app.js should consist of no code, other than a call to boot(), so I'm happy to move it into loopback, but, I read the loopback lib, and didn't see any evidence of this kind of console.log printing there. FWIW, I think app.js should look like: require('loopback').main(); and that main() should be clearly documented as a sequence of steps (kindof like the comments inline in the template now): Most customization could be done in boot files, we could auto-upgrade, new features would be automatically inherited by lb apps as long as they call app.main(), and if they needed to write their own main() for their specific loopback app, they are familiar enough with it to manually track future changes. boot() could do something like: Adding, removing, customizing middleware or other aspects of start sequence can then be done by adding/removing files. This is trivial to script. Right now, loopback has a fast cycle of new features, which is great, but there is no upgrade path for app.js, it looks like new features need to be added to app.js manually on upgrade, based on creating a new lb app, and manually copying new features over. |
|
I tried to move code to Note that in order to print the explorer location, it needs to know the baseeUrl, and it needs to know the explorer was actually configured. I don't see how to know this after-the-fact, but if you all know of some kind of "the middleware is running" API, perhaps its possible. I think some kind of generic, "annotated route" mechanism might be needed, so that its possible to programmatically walk the top-level routes, and report them to console if they are "annotated". I'll change the name to start. |
|
Test PASSed. To trigger a build add comment - ".test\W+please" |
Perhaps we can use // try to load loopback-explorer
if (explorerConfigured) app.set('looopback-explorer:path', explorerPath);
// inside app.run
var explorerPath = app.get('loopback-explorer:path');
if (explorerPath) // has explorer installedI have encountered a similar issue in strongloop/loopback-example-access-control#5, where I would like to access |
|
Test FAILed. To trigger a build add comment - ".test\W+please" |
The first chunk of code would be in app.js, the second in loopback core module. Having code in loopback core that depends on code in the loopback-workspace app template seems not so great, but if you are sure, I'll do. This comment was lost in the close/reopen, I think:
Some such loopback mechanism sounds great. Integrating such a mechanism in loopback is outside of my scope of SLN-683, I'm just removing the no longer needed code from the various templates and samples we have, so that they can run using (any) external supervisor, and to remove coupling of them to agent/cluster control. Maybe its in scope for example-access-control? |
|
I deleted my comment because I realised it's not that easy. There are two parts to this problem:
I am moving the discussion related to loopback-explorer to a new issue #34. |
|
Let's move this pull request forward. IMO the changes look good and can be merged. Refactoring of @ritch any objections? |
|
test please |
|
Test PASSed. To trigger a build add comment - ".test\W+please" |
|
Sounds good. We'll make a more structured change (might be loopback 1.5) to solidify |
|
Thanks for the comments, I'll merge this afternoon. |
|
Test PASSed. To trigger a build add comment - ".test\W+please" |
app.js is designed to be the package.main, so app can be required. If
its run as the main module (`node app.js`), then it also starts up.
Those features are desired, but the conditionality of startup in app.js
means it is difficult to start the app when run under a supervisor such
as strongloop/strong-supervisor or unitech/pm2. To fix:
- Create a single line server.js which unconditionally starts
- Add a .bin property to package.json so the app can be globally
installed.
- Exports the startup code as a function(`require('app.js').main` when
app is being used as a module (so behaviour of `node server.js` is
identical to `node app.js`).
|
Test PASSed. To trigger a build add comment - ".test\W+please" |
|
LGTM 👍 |
Allow app to be runnable with cluster
app.js is designed to be the package.main, so app can be required. If
its run as the main module (
node app.js), then it also starts up.Those features are desired, but the conditionality of startup in app.js
means there is way to start the app when run under a supervisor such as
strongloop/strong-supervisor or unitech/pm2. To fix:
installed.
require('app.js').mainwhenapp is being used as a module (so behaviour of
node server.jsis identical to
node app.js).they conflict with the supervisor's.