Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Deploying react project on Azure

I want to deploy my react project on azure cloud. I already deployed it on heroku and there it was very easy to deploy. I just had to do git push heroku master to deploy it on heroku. But I am clueless on how to do it on azure. So I have a bulid directory in my project which gets generated everytime I run gulp command. It has all the build files. Can anyone please guide me on how to proceed to azure?

This is my project structure

enter image description here

like image 841
EdG Avatar asked Feb 03 '17 12:02

EdG


People also ask

Does Azure support React?

To deploy a React app, you first need to create an app service on Azure. As the name suggests, an app service is a platform for building, deploying, and scaling web apps. Here are the steps: If you haven't already created an account on Azure, you can opt for a free account to follow this guide.

Can we host React app on Azure App Service?

You can deploy the react app to Azure App Service using VS code. Open your Project in VS Code. Go to Extensions. Search for Azure App Service and click on Install.


2 Answers

There are many options to deploy your app to azure websites/ web app, such as FTP, Local Git Repository, and Visual Studio IDE, etc. I am not a React expert, here for simplicity, I just use create-react-app tool and FileZilla to deploy my React app to Azure Web App. Here are the steps.

Basically, creating and building React app is as simple as

npm install -g create-react-app

create-react-app my-app
cd my-app/

npm run build

Now, the app is ready to be deployed! Let’s go into Azure portal and create a new website that will host our React app.

Enter a unique app service name, a valid name for the resource group and a new service plan. Then click Save.

enter image description here

To enable FTP publishing, click Deployment credentials under the APP DEPLOYMENT menu. Save the credentials and make a note of the user name and password you create.

enter image description here

Next, click on Properties, and copy the FTP HOST NAME and the USER.

enter image description here

Finally, connect to Azure Web app via FileZilla, then upload the entire content of the my-app/build folder created earlier into the /site/wwwroot/ folder on your Azure Website.

enter image description here

Now we can visit the app in a browser via URL: http://aaronreacttest.azurewebsites.net/, and it should display the default page.

enter image description here

like image 143
Aaron Chen Avatar answered Oct 17 '22 07:10

Aaron Chen


In addition to steps provided by Aaron, I had to add the web.config file with the content below. It is provided by other techies in their blogs and some forums.

<configuration>
  <system.webServer>
    <rewrite>
      <rules>
        <rule name="React Static Routes" stopProcessing="true">
          <match url=".*" />
          <conditions logicalGrouping="MatchAll">
            <add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" />
            <add input="{REQUEST_FILENAME}" matchType="IsDirectory" negate="true" />
            <add input="{REQUEST_URI}" pattern="^/(api)" negate="true" />
          </conditions>
          <action type="Rewrite" url="/" />
        </rule>
      </rules>
    </rewrite>
  </system.webServer>
</configuration>
like image 34
Prema Arya Avatar answered Oct 17 '22 08:10

Prema Arya