Reputation: 972
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
Upvotes: 15
Views: 30729
Reputation: 585
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.
Upvotes: 19