How to host reactjs and nodejs web app on azure vm IIS?

Sudesh Sharma 181 Reputation points
2021-03-09T09:50:09.797+00:00

I have created a web app with React and nodejs. Now I want to host web app on azure vm IIS web server. I have installed all necessary software i.e urlrewrite,iisnode etc.

I am confused about web.config file. How to write config file for both react js and nodejs? Can we write two rewrite rules inside one config file?

web.config file:

<configuration>
<system.webServer>

<httpProtocol>
<customHeaders>
<add name="Access-Control-Allow-Origin" value="*" />
</customHeaders>
</httpProtocol>

<handlers>
<add name="iisnode" path="server.js" verb="*" modules="iisnode" />
</handlers>
<defaultDocument>
<files>
<add value="server.js" />
</files>
</defaultDocument>

<rewrite>
<rules>
<rule name="React 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="/build/index.html" />
</rule>

<rule name="sendtonode">
<match url=".*"/>
<action type="Rewrite" url="server.js"/>
</rule>

</rules>
</rewrite>

</system.webServer>
</configuration>

Azure Virtual Machines
Azure Virtual Machines
An Azure service that is used to provision Windows and Linux virtual machines.
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Ryan Hill 30,326 Reputation points Microsoft Employee Moderator
    2021-03-09T15:08:36.42+00:00
    1 person found this answer helpful.
    0 comments No comments

Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.