简体   繁体   中英

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.

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. 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. 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 .

+--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? How should I fix my project in order to host it on 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. Now my API is hosted on Azure. I then deployed my client code to 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. 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. I think this is a separate issue I need to look into.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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