如何在同一服务器上运行多个StrongLoop

如何在同一服务器上运行多个StrongLoop

本文介绍了如何在同一服务器上运行多个StrongLoop LoopBack应用程序?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前正在运行两个 StrongLoop LoopBack 应用程序(Nodejs应用程序)在具有不同端口的单个服务器上.这两个应用程序都是从命令行使用slc lb projectslc lb model创建的.

I'm currently running two StrongLoop LoopBack apps (Nodejs apps) on a single server with different ports. Both apps were created using slc lb project and slc lb model from the command line.

是否可以在具有不同路径和/或子域的单个端口上运行这些应用程序?如果是的话,如何在Linux机器上做到这一点?

Is it possible to run these apps on a single ports with different path and/or subdomain? If it is, how do I do that on a Linux machine?

示例:

http://api.server.com:3000/app1/用于第一个应用程序.

http://api.server.com:3000/app1/ for first app.

http://api.server.com:3000/app2/用于第二个应用程序.

http://api.server.com:3000/app2/ for second app.

谢谢.

推荐答案

由于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);

这篇关于如何在同一服务器上运行多个StrongLoop LoopBack应用程序?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 22:08