So I’ve noticed that completing the weather api projects was very difficult as both APIs that were recommended block cross-origin requests and/or have SSL Issues so I came up with a quick hack to help you guys out. The API issues make it very frustrating to complete the challenges and I came up with a solution to help you guys.
The Heroku App (https://cors-anywhere.herokuapp.com/) seems to be another solution. You can even setup your own with https://github.com/Rob--W/cors-anywhere/ this is likely better than relying on my PHP Proxy that could break at any time.
Simply route your requests through https://apiproxy.nsuchy.me/proxy.php?url= [Put API URL Here] this is my free demo I’m providing, there isn’t any rate limiting other than Cloudflare’s, if you need a high request volume please follow the instructions to setup your own.
I don’t trust you / I wanna run my own:
No worries you’ll need to setup a web server running nginx and php; the source code for the proxy is as followed:
<?php echo file_get_contents($_GET['url']); ?>
Make sure to add:
add_header Access-Control-Allow-Origin *;
To your nginx configuration file in the php block or the requests will fail to work properly.
A quick note on the usage of API Proxies:
For quick development & testing, the use of an API Proxy is ok - however in a real-world environment you should hide API keys from the user to avoid API abuse from occurring under your application’s name. An alternative to an API Proxy is to use JSONP.
I hope this helps and good luck on your API Projects guys