I've scoured the web searching for a solution on how to deploy a React App on Microsoft's IIS.
I have successfully managed to deploy multiple Node.JS Applications but no such luck with React.
What I've tried:
installed URL Rewrite
I ran: npm i -g create-react-app
I created a basic react app: create-react-app my-app
I created a file called web.config
in ./public
route
web.config
<?xml version="1.0"?>
<configuration>
<system.webServer>
<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="/" />
</rule>
</rules>
</rewrite>
</system.webServer>
</configuration>
npm run build
new website
with Application Pool: DefaultAppPool
, the path linked to the ./build
folder directory.Site can't be reached
Error. Anyone else tried to deploy on IIS?
I've also tried the following resources: - https://github.com/react-boilerplate/react-boilerplate/issues/711 - https://www.quora.com/How-can-one-host-ReactJS-in-IIS - https://hackernoon.com/adding-web-config-to-react-projects-3eb762dbe01f
After that under the physical path section, you have to give the path of build folder & also give the port number where you want to host. Now right click on new website i.e ReactApp -> Manage Website -> Browse. Your react app is now successfully deployed. Now the next step is to add routing in our react application.
Open Control Panel and then click on the "Programs and Features". Click on "Turn Windows features on or off". Select Internet Information Services and click on the OK button. To see whether or not IIS is enabled, press Windows + R key and type inetmgr and click on OK.
I just tried this and it worked:
create-react-app myapp
yarn (or npm) build
If this doesnt work you may need to enable read/write access to the files so right click on the website and select edit permissions
Go to Security and hit edit, select Authenticated Users and on the bottom of the dialog check the modify/full control /read/write boxes where applicable. Do the same for your windows user that should be listed under Groups or user names section. Hit apply/save.
Right click the website and go to Manage Website then browse.
Boom.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With