Search code examples
reactjsamazon-web-servicesamazon-s3react-routeramazon-cloudfront

AWS on IE vs AWS on Chrome?


I host my ReactJs application on AWS with S3 & Cloudfront. I set up my routing with react-router-dom:

import { BrowserRouter, Route, Switch } from 'react-router-dom';
<BrowserRouter>
    <Switch>
      <Route path="/" component={App} exact />
      <Route path="/Aboutus" component={Aboutus} exact />

      <Route
      path="/FAQ"
      component={FAQ}
      exact
      />
      <Route path="/Anotherpage" 
      component={Anotherpage}
      exact 
      />
      <Route component={Error} />
    </Switch>
  </BrowserRouter>

Error is a 404 page which displays an error when a user tries to access an inexistent page. The problem is that now I host my reactjs application on AWS and when I use Chrome it returns my normal error, the 404 page.

When I use Microsoft Edge on AWS I am getting this instead:

<?xml version="1.0" encoding="ISO-8859-1"?>
<Error>
<Code>AccessDenied</Code>
<Message>Access Denied</Message>
<RequestId>D67C9C85E199DB09</RequestId>
<HostId>ENUq1f864JgnJjLbtAyo7Md0l1GMrA5u6....</HostId>
</Error>

I want to mention that it would work on localhost but not on AWS. Furthermore, this error also results when I try to access an existing page on Microsoft Edge. It doesn't happen on Google Chrome. Could it be from the bucket policies or permission restrictions?

Public access settings Bucket policy

When I am given the error page, despite it works on Chrome, I can see in the console the following errors:

> HTTP403: FORBIDDEN - The server understood the request, but is refusing to fulfill it. GET - https://websitelink.app/Anotherpage

SEC7120: [CORS] The origin 'https://websitelink.app' failed to allow a cross-origin script resource at'res://edgehtml.dll/xmltreeview.js'.


Solution

  • I found the answer! Basically Google Chrome was bypassing such errors and operate with react router to return the page. In order to make it work on Microsoft Edge I had to:

    1) Go the Cloudfront

    2) Edit custom error response

    3) Change HTTP code to 403:Forbidden; Customize error response: Yes; Response page path: /Index.html ; HTTP Response code: 200: OK

    Then I invalidate cache and it works.

    Hope it helps future people.

    Only link that helped me