将Node.js服务器和angular应用程序部署到Azure Web服务

问题描述:

我有一个Angular应用程序(9.1.4)和一个node.js服务器应用程序(12.14.1).我的文件当前配置如下:

I have an Angular app (9.1.4) and a node.js server application (12.14.1). My files are currently configured like this:

MyApp
- package.json
- angular.json
- server
  - server.js
- src
  - app
  - asserts
  - environments
  - angular html/css/ts
- node_modules

为了在本地破坏他,我必须在一个cmd提示符下运行node server.js,在另一个cmd提示符下运行ng serve.我希望将该项目部署到Azure,但是不确定如何设置它以便可以在单个应用程序服务中运行.所以:

In order to runt his locally I have to run node server.js in one cmd prompt and ng serve in another. I hope to deploy this project to Azure but am not sure how to set this up so that it can run in a single app service. So:

  1. 如何通过本地同一命令运行服务器(node.js)和应用程序(角度)?
  2. 一旦我在本地进行了此设置,需要更改什么(如果有的话)才能在Azure中运行?

首先,项目的启动端口,前端有角项目和后端节点服务是否在同一配置文件中?

First of all, are the startup ports of your project, front-end angular project and back-end node service in the same configuration file?

  1. 如果是,那么您可以通过修改package.json文件中的脚本来执行多个命令.

  1. If yes, then you can execute multiple commands by modifying the script in the package.json file.

因为azure Web应用程序仅支持44380端口.如果两个项目的端口配置不同,则可能在本地正常运行.

Because only 443 and 80 ports are supported in azure web app. If the port configuration of the two projects is not the same, it may run normally locally.

例如,ng项目为7001,服务器项目为7002,并根据process.env.PORT参数部署到azure Web应用程序,它将导致端口冲突,并且无法启动该项目.

For example, the ng project is 7001, and the server project is 7002, deployed to the azure web app, according to the process.env.PORT parameters, it will the port conflicts and the project cannot be started.

因此,如果是第二种情况,该如何处理:

您可以使用虚拟应用程序分别部署应用程序.有关更多详细信息,您可以在另一篇文章中看到我的答案.

You can use virtual applications to deploy your applications separately. For more details, you can see my answer in another post.