For those of you who are stuck on the Weather API Projects

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.

UPDATE:
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.


API Proxy:
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 :slight_smile:

6 Likes

Hi @anon52159105,
Good post. I got around this problem by installing the CORS Chrome extension

https://chrome.google.com/webstore/detail/cors-toggle/omcncfnpmcabckcddookmnajignpffnh?hl=en

Seems to work really well. Just remember to turn it off when not coding as it’s a security risk.

Cheers
RockLobster7

At a minimum you’ll need to put in the footer, otherwise the project might not count as passing when it’s reviewed.

For production you should hide your API Keys, for a learning project that’s not a priority.

That might be worth adding to the project descriptions.

I’ve added it as a quick note.

1 Like