Cannot GET index.html Azure Linux Web App

后端 未结 3 431
后悔当初
后悔当初 2020-12-10 05:53

We created a Linux Web App in Microsoft Azure. The application is static written with React (html and Javascript). We copied the code into the wwwroot folder, but the applic

3条回答
  •  借酒劲吻你
    2020-12-10 06:38

    MAY 2020 - You don't have to add any javascript files or config files anywhere. Let me explain.

    I was facing this exact same issue and wasted 6 hours trying everything including the most popular answer to this question. While the accepted answer is a nice workaround (but requires more work than just adding the index.js file), there's something a simpler than that.

    You see, when you just deploy an Azure Web App (or App Service as it is also called), two things happen:

    1. The web app by default points to opt/startup/hostingstart.html

    2. It also puts a hostingstart.html in home/site/wwwroot

    When you deploy your code, it replaces hostingstart.html in home/site/wwwroot but the app is still pointing to opt/startup/hostingstart.html. If you want to verify this, try deleting opt/startup/hostingstart.html file and your web app will throw a "CANNOT GET/" error.

    So how to change the default pointer? It's simpler than it looks:

    Go to Configuration tab on your web app and add the following code to startup script:

    pm2 serve /home/site/wwwroot --no-daemon
    

    If this web app is a client-side single-page-app and you're having issues with routing, then add --spa to the above command as follows:

    pm2 serve /home/site/wwwroot --no-daemon --spa
    

    This will tell the web app to serve wwwroot folder. And that's it.

    Image for reference: Screenshot explaination

    PS: If you only set the startup script without deploying your code, it will still show the hostingstart.html because by default that file lies in the wwwroot folder.

提交回复
热议问题