1

I am using AWS codestar to deploy by react application using serverless nodejs template. This is the url that is given by codestar after successfully completion of all the stages https://xxxxx.execute-api.us-east-1.amazonaws.com/Prod . This url displayed all the components in my app correctly. In navbar of my app i have items like this a ,b,c. where clicking on each one of them will redirect to a new component.(i.e.https://xxxxx.execute-api.us-east-1.amazonaws.com/a,https://xxxxx.execute-api.us-east-1.amazonaws.com/b etc. But when i refresh the page which is having a url like this https://xxxxx.execute-api.us-east-1.amazonaws.com/b i am getting a error like {"message":"Forbidden"} and in my console it is showing like this favicon.ico:1 GET https://xxxx.execute-api.us-east-1.amazonaws.com/favicon.ico 403

It seems the chrome is fetching the favicon based on the https link, which fails because there is no such favicon at the location. I tried to remove favicon.ico link in index.html but even then the chrome is using the same url to fetch the favicon which eventually fails. I followed max number of suggestions in SO to acheive this but no luck. Is there any way to say api-gateway to exclude these favicon get requests and display my app rather than showing message forbidden.

And i am pretty sure that i had enabled logs for both the agi-gateway and lambda where i didnt find any forbidden errors(i.e.403) which is weird because i can see those 403 errors in my console.

Thanks Any help is highly appreciated.

Private
  • 1,661
  • 1
  • 20
  • 51

1 Answers1

2

The https://xxxxx.execute-api.us-east-1.amazonaws.com/Prod url provided by API Gateway is the base url for your site, so those paths would have to be /Prod/a instead of /a.

One way to get around that is to register your own domain and connect it to API Gateway via a custom domain. That would allow you to have https://example.com as your base url, and your paths could stay /a, /b, etc.

Tom
  • 1,660
  • 8
  • 16
  • Thanks @Tom. You mean because of this i am getting `{"message":"Forbidden"}` ? Is it not due to `favicon get requests` ? – Private Sep 29 '18 at 03:27
  • Your favicon requests are failing since `https://xxxxx.execute-api.us-east-1.amazonaws.com/favicon.ico` has the wrong url base. I think favicons are requested by browsers automatically at `/favicon.ico`, so you may not be able to change the path to `/Prod/favicon.ico`. – Tom Sep 29 '18 at 05:54
  • Yeah what you are saying is exactly right regarding the favicon thing. In your answer you said one way is through custom domain is there any other way for that since i dont have custom domain because it is not free. – Private Sep 29 '18 at 10:48
  • It looks like browsers request `/favicon.ico` without looking at the page's base url, so even providing a[](https://www.w3schools.com/TAGs/tag_base.asp) tag wouldn't help. So I don't see another way around the favicon issue. Using a tag could at least simplify your links though, so you wouldn't need `/Prod` in front of all of them. – Tom Sep 29 '18 at 20:56
  • Thanks for the `` tag. One question even after using custom domain still it will read the same url right ? Suppose i have custom domain like this `https://www.example.com` then i will assign this with the base url(i.e.`https://xxxxx.execute-api.us-east-1.amazonaws.com/Prod`) . After that i will assign paths to my custom domains like this `https://www.example.com/a`,`https://www.example.com/b` etc. Then when i hit this `https://www.example.com/a` in browser internally it points to `https://xxxxx.execute-api.us-east-1.amazonaws.com/Prod/a` only right? – Private Sep 30 '18 at 07:24
  • Because i already tried `https://xxxxx.execute-api.us-east-1.amazonaws.com/Prod/a` one without custom domain and it given me `{"message":"Missing Authentication Token"}` – Private Sep 30 '18 at 07:27
  • Yeah, `https://www.example.com/a` would become the equivalent of hitting `https://xxxxx.execute-api.us-east-1.amazonaws.com/Prod/a`. The authN token is a separate issue and is due to your authN type being set to something other than NONE. If you use an authN mechanism, you'll need to provide appropriate credentials (like IAM if your authN is AWS_IAM); otherwise you can just use NONE to not require authN. – Tom Sep 30 '18 at 16:59