有没有办法使用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.
更多推荐
发布评论