Switch to HTTPS?

Switch to HTTPS?
0

#1

What’s up fellow coders!

For my weather app, I decided to read the position from navigator.geolocation in JavaScript. However, modern browsers such as Chromium stricly require the page to be loaded over a secure HTTPS connection for this feature to work.
This leads to issues when getting weather data from OpenWeatherMap.org, who only serve their API over HTTP. To solve this and have my app work fully over a secure connection, I tried switching to forecast.io, however their API doesn’t allow for Cross-Origin Requests. Both OpenWeatherMap and Forecast won’t work for this project.

Suggestions are welcome.


#2

Well, you can also try getting coordinates by ip as backup. I haven’t had that sort of problem though. Tried on Opera (chrome works flawless and firefox jumps on the ip if i don’t allow geolocation) and it won’t work if i have the Opera ad block on. Maybe you have a similar problem.


#3

Get your codepen HTTPS and the call to forecast.io in HTTPS also, this should resolve any issues you had with CORS !


#4

The forecast.io API doesn’t send the Cross-Origin Request headers that are required to make API calls from the browser. It will not send this header regardless if it’s a HTTP or HTTPS request. The forecast.io API documentation specifically links to a JavaScript wrapper with PHP proxy as a workaround, which I don’t want to use for this project.


#5

if you are using $.getJSON to make the api call, add ?callback=? at the end of your query. This will make a JSONP request instead that will work.

Read up on JSONP here


#6

Thank you, I think JSONP is an ugly hack but I’ll use it for now.