在两个不同的主机上托管Angular应用程序(Hosting an Angular application on two different hosts)

编程入门 行业动态 更新时间:2024-10-18 14:14:54
在两个不同的主机上托管Angular应用程序(Hosting an Angular application on two different hosts)

有没有办法使用Node.js在两个不同的主机(不同的IP或不同的端口)上托管相同的Angular应用程序?

Is there any way to host the same Angular app on two different hosts (different IP or different port) using Node.js?

最满意答案

.angular-cli.json文件允许您指定Angular-CLI配置选项; 包括默认主机名和端口。

serve: Properties to be passed to the serve command • port (number): The port the application will be served on. Default is 4200. • host (string): The host the application will be served on. Default is localhost.

您可以通过定义如下属性来定义.angular-cli.json文件中的已使用端口:

{ "defaults": { "serve": { "port": 2500 } } }

有关更多信息和完整的配置选项列表,请参阅Angular CLI文档: https : //github.com/angular/angular-cli/wiki/angular-cli


命令行解决方案

如果您正在寻找不需要和配置编辑的命令行解决方案,只需使用可选的host和port命令运行ng serve或ng serve --prod命令。

ng serve --host 0.0.0.0 --port 4201

使用这些可选的命令行参数,您只需运行两次命令,每个命令具有不同的主机和端口。


旁注:话虽如此,除非您打算使用Angular CLI为Angular应用程序提供服务,否则您可能需要使用与托管平台关联的方法配置这些选项。

The .angular-cli.json file allows you to specify Angular-CLI configuration options; including the default hostname and port.

serve: Properties to be passed to the serve command • port (number): The port the application will be served on. Default is 4200. • host (string): The host the application will be served on. Default is localhost.

You can define the used port in the .angular-cli.json file by defining the property like this:

{ "defaults": { "serve": { "port": 2500 } } }

See the Angular CLI documentation for more info and a complete listing of configuration options: https://github.com/angular/angular-cli/wiki/angular-cli


Command line solution

If you're looking for a command line solution that does not require and configuration editing, simply run the ng serve or ng serve --prod commands with the optional host and port commands.

ng serve --host 0.0.0.0 --port 4201

Using these optional command line parameters, you can simply run the command twice, each with different a host and port.


Side note: That being said, unless you are going to be serving your Angular application using the Angular CLI, you'll likely need to configure these options using the methods associated with your hosting platform.

更多推荐

本文发布于:2023-07-14 14:26:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1105082.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:应用程序   两个   主机   application   hosts

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!