Just a heads up to anybody thinking of using OpenWeatherMap to get their weather data for this project: to use the JavaScript geolocation API you have to be running over a HTTPS connection, if you’re running over a HTTPS connection then all your external API requests must also go over a HTTPS connection. The problem is that OpenWeatherMap only allow HTTPS requests if you pay them money.
I built my project using some test data that I grabbed from them (to prevent excessive API calls, which they limit to a certain number per hour) and so I only found out that my project wouldn’t actually work after I’d already built it around OpenWeatherMap.
Hopefully somebody reads this before making the same mistake.
index.html:1 XMLHttpRequest cannot load https://crossorigin.me/http://api.openweathermap.org/data/2.5/weather?lat=...&lon=...&appid=.... No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'https://s.codepen.io' is therefore not allowed access. The response had HTTP status code 522.
Well this link seems to be up all the time (that crossorigin.me isn’t working). Unless you want to use your app regularly, I don’t see a problem. I suppose it is not a clean solution to add such a link to your api url, but it works great as a quick fix. If you now upfront that you will need this, you might want to search for another api.
But, I have’t used cors-anywhere much, so I don’t know if it is faster.
From a cursory glance at the crossorigin.me Twitter account it seems it isn’t a new problem. I guess they just don’t have enough bandwidth/resources and so the server gets overloaded.
I had the same problem with codepen. I finished my weather app a while ago, and when I tried using it recently, it didn’t work. Well, while struggling to figure out what to do, I realized I could try accessing my codepen using HTTP instead of HTTPS. Viola! It works now.
Basically a simple solution is to make sure campers share their codepen link using HTTP.
In my case my problems aren’t over, since I just moved my portfolio to a vps, and I’m serving all content through HTTPS (https://alexandroperez.com) I’m planning on having every app live in a subdomain, which will be served through HTTPS as well… I guess I’ll have to make nodejs handle the json request on the server or something similar. Though I’m new to nodejs…