React App not starting in azure app service

前端 未结 5 1382
天命终不由人
天命终不由人 2020-12-10 18:00

I\'ve deployed a simple react app to azure app service and it won\'t start:

How do I get the app to run index.html?

5条回答
  •  醉话见心
    2020-12-10 18:42

    If you deployed to a Node Linux Web App the default document would be hostingstart.html located in /home/site/wwwroot/.

    According to this:

    When you create a Node.js app, by default, it's going to use hostingstart.html as the default document unless you configure it to look for a different file. You can use a JavaScript file to configure your default document. Create a file called index.js in the root folder of your site

    So go to your ssh terminal, navigate to /home/site/wwwroot. Create index.js there with the following code:

    var express = require('express');
    var server = express();
    var options = {
    index: 'index.html'
    };
    server.use('/', express.static('/home/site/wwwroot', options));
    server.listen(process.env.PORT);
    

    NOTE: Be sure to run npm install --save express also in this folder else your app service will crash on startup

    Restart, it will configure index.html as the default document for your app.

提交回复
热议问题