I followed this tutorial to deploy a react app to and Azure WebApp
https://medium.com/#to_pe/deploying-create-react-app-on-microsoft-azure-c0f6686a4321
After I uploaded the Build folder via FTP, when I access the url i get the following message:
"You do not have permission to view this directory or page."
I tried with and without the web.config file.
Log Presented by the App
I then tried adding this to the web.config file but then it just renders a white page with the correct Page Title.
<defaultDocument enabled="true">
<files>
<add value="build/index.html" />
</files>
</defaultDocument>
I assume because it can't access the referenced .js files in the index.html.
I went to deployment options. Configured my local Git Repository.
Configured my local Git. Then inside the build folder ran:
git init
git add .
git commit -m "initial build"
git remote add <azure your-git-clone-url>
git push azure master
And it now runs
I've also followed the tutorial that you've tried.
Sometimes it works and sometimes it doesn't work.
Problem
Even after I've restarted my server, the new static content was not reflected to endpoint. (eg. https://my-endpoint.azurewebsites.net)
Or routing is not updated properly with my web.config.
Environment
Webapp(Node 10.14 + Windows), FileZilla of MacOS
Source Code: React-boilerplate
Solution
Copy and paste all files in build directory into server's webroot directory except web.config
Then, copy and paste web.config
Comment
I don't know why Azure not works as my expectation.
I've made several Azure Web app for deployment. Whenever I've created new Azure web app, some instance is updated with web.config trigger and other instance is updated with index.html trigger. However, depending on my experience, web.config looks final trigger.
If you trouble with some 4xx, 5xx error which is not mentioned in tutorial page from your Web app , just delete web app and create another new one. I also tried to connect DevOps CI/CD pipeline in Azure to Web app. However, after success build and deployment process, my site is not updated and there was no files in directory of server(I checked via FileZilla)
After that, direct FTP deployment not working. The only solution for me was deleting it and creating new Web app.
I spent my 2-3 days due to this issue. If anybody have advice or right guide or right information about Azure's internal logic for my case, please comment it for saving my few weeks in future.
Web.config
Below is mine from the tutorial
<?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>
Related
For production mode, I need to compress my react project to gzip files for better performance. So I've compressed my react files with compression-webpack-plugin same as bellow in webpack.config:
plugins: [
new CompressionPlugin({
algorithm: 'gzip',
test: /\.(js)$|\.(css)$|\.(html)$|\.eot?.+$|\.ttf?.+$|\.woff?.+$|\.svg?.+$/,
})
],
Here's the output folder:
I'm using Url rewriter to load pre-gzip files on server instead of original js files on web.config:
<rewrite>
<outboundRules rewriteBeforeCache="true">
<rule name="Custom gzip file header">
<match serverVariable="RESPONSE_CONTENT_ENCODING" pattern=".*" />
<conditions>
<add input="{REQUEST_URI}" pattern="\.gz$" />
</conditions>
<action type="Rewrite" value="gzip"/>
</rule>
</outboundRules>
<rules>
<rule name="Rewrite gzip file">
<match url="(.*)"/>
<conditions>
<add input="{HTTP_ACCEPT_ENCODING}" pattern="gzip" />
<add input="{REQUEST_FILENAME}.gz" matchType="IsFile" />
</conditions>
<action type="Rewrite" url="{R:1}.gz" />
</rule>
</rules>
</rewrite>
In addition I've installed Internet Download Manager on my OS. The problem which I have is that Internet download manager, download gz files and it has lead to website doesn't work properly! Here's the picture of the problem:
How can I not let a third party application such as Internet Download Manager, stay between the response which is sent from the server and client which want to received it and gzip files works properly?
I think you are making a wrong request, you should make a request to vendor.js, and not vendor.js.gz (probably in your HTML). I never worked with IIS but the server should be configured in a way that if it gets the request header Accept-Encoding: gzip then it passes the gzipped file with the response header of Content-Type: gzip.
For example, if you look at StackOverflow requests, it gets some .js files with the response header of Content-Type: gzip. This tells the browser that the content should be uncompressed first.
As you can see in the images, it's only a request to a .js file.
The following steps could help:
in the Internet Download Manager, open the options;
select file types;
you can either edit the file type (e.g. GZ, GZIP) or edit the sites list that don’t start downloading automatically
I'm trying to upload my website onto the web. I have two folders for holding my front-end React files and another for the back-end files that uses Nodejs, cors, and express. It also has my API and middleware.
The front-end pages have already been uploaded onto my IIS and port forwarded with my router, so I can access that anywhere with my IP. But it doesn't function well without my backend files, how can I host the backend files as well and make them work together?
I am getting a headache doing this, does anyone know how to do this??
Thanks in advance.
As far as I know, if you want to host node.js application, you should firstly install the node.exe and the a build of iisnode.
node.exe
iisnode
After installed the IIS nodes, you could set up samples, from the administrative command prompt call %programfiles%\iisnode\setupsamples.bat.
Then you could go to http://localhost/node to see the example.
The next step is to deploy the node.js application inside one iis web application.
Lastly, you should create or modify the web.config to use the iisnode modules.
For example,
<configuration>
<system.webServer>
<handlers>
<add name="iisnode" path="app.js" verb="*" modules="iisnode" />
</handlers>
<rewrite>
<rules>
<rule name="mysite">
<match url="/*" />
<action type="Rewrite" url="app.js" />
</rule>
</rules>
</rewrite>
<defaultDocument>
<files>
<add value="app.js" />
</files>
</defaultDocument>
</system.webServer>
More details, you could refer to below article:
https://www.hanselman.com/blog/InstallingAndRunningNodejsApplicationsWithinIISOnWindowsAreYouMad.aspx
How can i host reactjs app in IIS webserver?
I used npm run build and replaced the file into the server and create new site which refers to those file.
also i add the binding all IP to port 80 using * sign.
but not worked.
After we run the below command, the output will create a new folder called “build” inside the project which contains production build. We could host the project by copying these files to the root directory of the IIS website, the website root folder should be able to be accessed properly by the anonymous account, and therefore we should grant IUSR account full access to the folder if it is not the default website.
After adding the web site binding in IIS binding module,
We could access the website properly by using the below address.
http://localhost
Besides, if we adding certain routing features (multiple components) in the react application, we have to install the IIS URL Rewrite extension.
https://www.iis.net/downloads/microsoft/url-rewrite
After a successful installation, we need to create a web.config file containing the below content under the root directory of the IIS website.
<?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>
Feel free to let me know if the problem still exists.
My AngularJS app requires all actions to redirect to index.html for processing and it works fine on localhost, but it doesn't work in Azure.
For example:
localhost:1234 -> localhost:1234/#/ works
myapp.com -> myapp.com/#/ doesn't work
myapp.com/index.html -> myapp.com/index.html#/ works
I added:
<system.webServer xdt:Transform="Replace">
<rewrite>
<rules>
<rule name="redirect all requests" stopProcessing="true">
<match url="^(.*)$" ignoreCase="false" />
<conditions logicalGrouping="MatchAll">
<add input="{REQUEST_FILENAME}" matchType="IsFile" negate="true" pattern="" ignoreCase="false" />
</conditions>
<action type="Rewrite" url="index.html" appendQueryString="true" />
</rule>
</rules>
</rewrite>
</system.webServer>
The weird thing is that this works sometimes. I can't for the life of me figure out why sometimes going to myapp.com -> myapp.com/#/ works and other times it doesn't. It seems to also break myapp.com/index.html#/ but only sometimes. This is without making any deployment changes. It just works about half the time.
Edit
Here is the actual error message:
Microsoft.Owin, Version=2.1.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35' or one of its dependencies. The located assembly's manifest definition does not match the assembly reference. (Exception from HRESULT: 0x80131040)
It might be about application startup. Here are some troubleshooting ideas.
Restart your app. Does that reliably cause the error?
Turn on application logging. portal.azure.com > Browse All > The Site Name > Settings > Diagnostic logs > Application Logging > Level Error. If you want lots of stuff, set level to verbose and turn on web server logging, detailed error messages, and failed request tracing.
View diagnostics at service control manager mysite.scm.azurewebsites.net. Choose Debug console > PowerShell. Now you can look through the logs at home/LogFiles.
Based on the error you are receiving, it looks like Owin is the problem. Check your websites bin to see if there are any Owin references. From the online service control manager, you can try this:
cd site/wwwroot/bin
Get-ChildItem -filter *Owin*
If there is anything there, then it's probably the cause of the particular error you are receiving.
I am finishing up a new mobile website to compliment the desktop version. Currently I have a rewrite rule in the web.config file on my desktop site that looks like so:
<system.webServer>
<rewrite>
<rules>
<rule name="MobileRedirect" patternSyntax="ECMAScript" stopProcessing="true">
<match url=".*" ignoreCase="true" />
<conditions logicalGrouping="MatchAll">
<add input="{HTTP_COOKIE}" pattern="nomobile" ignoreCase="true" negate="true" />
<add input="{HTTP_USER_AGENT}" pattern="android|blackberry|googlebot-mobile|iemobile|iphone|ipod|opera mobile|palmos|webos" />
</conditions>
<action type="Redirect" url="http://m.mysite.com" appendQueryString="false" redirectType="Found" />
</rule>
</rules>
</rewrite>
This works perfect if I never want the user to be able to use the desktop site while on a mobile device, but that is not always the case. Some links on the mobile site DO link back into the desktop version. I have a link on the footer of the mobile site to "view full site" as well.
So my question IS: how to properly handle cookie setting on that link and then detecting in the web.config and NOT redirecting to the mobile version IF it exists.... I have a conditional check in the web.config for http_cookie "nomobile", but I don't think it is properly working. Do I just send in a querystring value from the mobile and check that in the global.asax file or does that not work because the web.config runs first?
The desktop is a C# MVC4 site on IIS 7.5 if any of that helps, and the mobile site is a simply jquery mobile site.
Thank you!
EDIT:
I have tried checking the querystring in the global.asax file (code below) but it seems that "Request is not available in this context".
// create and set cookie if ?nomobile detected
string forcedesktop = HttpContext.Current.Request["nomobile"];
if(forcedesktop != null){
HttpCookie nomobile = new HttpCookie("nomobile");
Request.Cookies.Add(nomobile);
}
}