Closed EricHasegawa closed 3 years ago
This is still supposed to work. You'd have to be a bit more specific: what code are you using to create the request, what's are the request headers + response headers and network log (see browser's devtools).
Thanks for the reply! I'll provide details below.
1) I followed these steps
git clone https://github.com/Rob--W/cors-anywhere.git cd cors-anywhere/ npm install heroku create git push heroku master
2) This created my proxy here https://shrouded-escarpment-45572.herokuapp.com/
3) I wrote a basic function to call an API
async function getLocation() { let response = await fetch("https://shrouded-escarpment-45572.herokuapp.com/https://api.bigdatacloud.net/data/client-ip"); console.log(response); }
(this API just gets the calling users IP, no key needed or anything)
Running this function returns the following object:
If you have any more questions please ask as I am happy to provide anything else that might help. Cheers!
p.s. sorry I am not sure how to handle newlines on github lol
The server seems to work based on the screenshot that you've provided (in particular the status code is visible and 200
). To read the response text, also add the following to view the response.
let responseText = await response.text();
console.log(responseTex);
p.s. sorry I am not sure how to handle newlines on github lol
To have inline code, use one back-tick. To format code blocks, use three backticks. See https://guides.github.com/features/mastering-markdown/
I think this is working now, but unfortunately the IP it is reading says I am an AWS EC2 server. Is this because it is detecting the IP of the heroku server that this is deployed on?
I think this is working now, but unfortunately the IP it is reading says I am an AWS EC2 server. Is this because it is detecting the IP of the heroku server that this is deployed on?
Yes. That's correct. Any other answer would be wrong.
The X-Forwarded-For header can be used to guess the original IP, but that header can only be trusted by a server if it was set by a proxy that it can trust, for example a load balancer that sits between an application server and the external client.
Thanks so much!!
I followed the exact instructions here: https://stackoverflow.com/questions/43262121/trying-to-use-fetch-and-pass-in-mode-no-cors,
and am making my API request via https://.herokuapp.com/
I am still receiving cors errors here. Am I doing something wrong, or did this stop working?