Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

create-react-app on IIS 10

Tags:

iis

reactjs

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:

  1. installed URL Rewrite

  2. I ran: npm i -g create-react-app

  3. I created a basic react app: create-react-app my-app

  4. 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>
  1. I then ran npm run build
  2. In IIS I added a new website with Application Pool: DefaultAppPool, the path linked to the ./build folder directory.
  3. I ran browsed to the App
  4. I get a 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

like image 347
Justin Avatar asked Aug 13 '18 13:08

Justin


People also ask

Can we deploy React app on IIS?

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.

How do I run a React app in IIS?

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.


1 Answers

I just tried this and it worked:

create-react-app myapp

yarn (or npm) build

  • Open IIS manager and create a new website
  • Point it at your build folder in the newly created react project
  • Create a new application pool
  • Right click on the app pool and under Process model find Identity, click the three dots
  • Select custom and enter your windows credentials.

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.

like image 129
molebox Avatar answered Oct 19 '22 05:10

molebox