本文介绍了将 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 并在另一个提示符下运行 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) 和应用程序 (angular)?
  2. 在本地完成此设置后,需要更改哪些(如果有的话)才能在 Azure 中运行?

推荐答案

首先,你的项目的启动端口,前端的angular项目和后端的node服务在同一个配置文件里吗?

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,server项目为7002,根据process.env部署到azure web app.PORT参数,会导致端口冲突,项目无法启动.

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.

这篇关于将 node.js 服务器和 Angular 应用程序部署到 azure Web 服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-22 16:06
查看更多