Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cannot GET index.html Azure Linux Web App

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 application only showing only hostingstart.html and when we try to get page index.html we have this error: Cannot GET /index.html

We tried with a sample of Azure in GitHub (https://github.com/Azure-Samples/html-docs-hello-world) but the error is the same. The url is this: https://consoleadmin.azurewebsites.net/index.html

Last week the application was running correctly.

We forget to do something?

like image 773
invisibleProgrammer Avatar asked Jan 17 '19 13:01

invisibleProgrammer


People also ask

How do I add HTML code to Azure Web App?

Open Visual Studio and go to Open -> Web Site, select the HTML file path from your local directory. 3. Once HTML and the dependent Javascript files are loaded, go to "Publish Web App", right-click on project, and you will see the option to open to publish.

Can HTML be deployed with Azure?

Azure App Service provides a highly scalable, self-patching web hosting service. This quickstart shows how to deploy a basic HTML+CSS site to Azure App Service. You'll complete this quickstart in Cloud Shell, but you can also run these commands locally with Azure CLI.

How do I enter my Azure Web app code?

In the browser, navigate to https://<app_name>.scm.azurewebsites.net/ZipDeployUI . Upload the ZIP package you created in Create a project ZIP package by dragging it to the file explorer area on the web page.


1 Answers

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.

like image 125
DeityWarrior Avatar answered Sep 22 '22 04:09

DeityWarrior