更新时间:2023-11-22 18:19:34
由于LoopBack应用程序是常规的Express应用程序,因此可以将它们安装在主应用程序的路径上.
Since LoopBack applications are regular Express applications, you can mount them on a path of the master app.
var app1 = require('path/to/app1');
var app2 = require('path/to/app2');
var root = loopback(); // or express();
root.use('/app1', app1);
root.use('/app2', app2);
root.listen(3000);
明显的缺点是app1和app2之间的运行时耦合度很高-每当您升级它们中的任何一个时,都必须重新启动整个服务器(即,它们两者).同样,一个应用程序发生致命故障也将导致整个服务器瘫痪.
The obvious drawback is high runtime coupling between app1 and app2 - whenever you are upgrading either of them, you have to restart the whole server (i.e. both of them). Also a fatal failure in one app brings down the whole server.
由于每个应用程序都是独立的,因此@fiskeben提出的解决方案更加强大.
The solution presented by @fiskeben is more robust, since each app is isolated.
另一方面,我的解决方案可能更易于管理(您只有一个Node进程,而不是nginx +每个应用程序的Node进程),并且还允许您配置两个应用程序共享的中间件.
On the other hand, my solution is probably easier to manage (you have only one Node process instead of nginx + per-app Node processes) and also allows you to configure middleware shared by both apps.
var root = loopback();
root.use(express.logger());
// etc.
root.use('/app1', app1);
root.use('/app2', app2);
root.listen(3000);