简体   繁体   English

将客户端和服务器Node.js应用程序部署到Azure

[英]Deploying client and server nodejs apps to Azure

I set up my project with two apps in the root directory initially, one for the client and one for the server. 我最初在根目录中使用两个应用程序设置了项目,一个用于客户端,一个用于服务器。 My directory looks like this: 我的目录如下所示:

+--root
   |--client
   |    |--node_modules
   |    |--package.json
   |
   |--server
        |--node_modules
        |--package.json

I would run npm start in each directory respectively to start the client code, which had the code for the React components and Routes and the server code for the REST api. 我将分别在每个目录中运行npm start来启动客户端代码,该客户端代码具有React组件和Routes的代码以及REST api的服务器代码。

I'm now trying to deploy my project on Azure and I can't get it to work now like the tutorials suggest I should. 我现在正在尝试在Azure上部署我的项目,但现在却无法像教程中建议的那样正常工作。 I reorganized my package structure to look use one package.json now, but I still run into the problem that I need to run two applications after deploying to Azure in order for my website to function. 我重新组织了程序包结构,现在看起来只使用一个package.json,但是仍然遇到问题,我需要在部署到Azure之后运行两个应用程序才能使我的网站正常运行。 This is what my directory looks like now and I'm using concurrently to run my custom commands, npm run client and npm run server . 这是我的目录现在的样子,并且我正在同时使用它来运行自定义命令, npm run clientnpm run server

+--root
   |--client
   |--server
   |--node_modules
   |--package.json

Yet I still cannot get my site to run. 但是我仍然无法运行我的网站。 Is it because there is no index.html at the wwwroot after it is deployed? 是因为部署后wwwroot上没有index.html吗? How should I fix my project in order to host it on Azure? 我应该如何修复我的项目以将其托管在Azure上?

I managed to host my server side code by setting up a new nodejs project in Azure and then copying over my server code into that project. 通过在Azure中设置新的nodejs项目,然后将服务器代码复制到该项目中,我设法托管了服务器端代码。 Now my API is hosted on Azure. 现在,我的API托管在Azure上。 I then deployed my client code to heroku. 然后,我将客户代码部署到heroku。 This worked like a charm, it detected the package.json and automatically ran the npm start script which started the client and read the webconfig to know to use the src/index.js as the starting point for my app. 这就像一个魅力一样,它检测到package.json并自动运行npm start脚本,该脚本启动了客户端并读取了webconfig,以知道将src / index.js用作我的应用程序的起点。 I presume it also started my server code as well, since my npm start command runs the npm run server command also via concurrently but it doesn't look like the client is able to reach the API via the local host url I was using. 我猜想它也同样启动了我的服务器代码,因为我的npm start命令还通过并发运行了npm run server命令,但是看起来客户端无法通过我使用的本地主机URL来访问API。 I think this is a separate issue I need to look into. 我认为这是我需要研究的单独问题。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM