jdemaeyer / brightsky

JSON API for DWD's open weather data.
https://brightsky.dev/
MIT License
290 stars 18 forks source link

Publish the code of the demo page? #105

Closed BeyondVertical closed 3 years ago

BeyondVertical commented 3 years ago

Hey there, I really like Bright Sky - thanks for your development. As I want to use pretty much exactly the simple weather app you have on the demo page, I wanted to ask, if you could publish the code of this. It would be really helpful to me, as I am not that into JavaScript and the demo app is just perfect for my use case. Thank you for considering my proposal and for the continued development!

jdemaeyer commented 3 years ago

Heyho @BlackScreen, thanks for the kind words!

It's already published in this repo under the docs/demo folder :) (with the JavaScript starting on line 92)

I'm closing this for now but feel free to re-open if you think something's missing!

BeyondVertical commented 3 years ago

@jdemaeyer Thanks for the help, I just did not see that here. Sorry for that. I copied the whole "demo" folder over to my webspace, but the whole block of the response and the app block do not refresh when I change parameters - unlike on your page. I do not know why. Any idea what I am doing wrong? :/

Never mind, I think I found the error with the developers tools in Chrome. Have to check for that error... image

BeyondVertical commented 3 years ago

Ok, if I understand correctly this error is solveable with adding a ".htaccess" to your server and adding this to the file:

<IfModule mod_headers.c>
    Header set Access-Control-Allow-Origin *
</IfModule>

I am obiously no expert on this, but reading this and a few other results on Google seem to hint to this. Would adding the header be an option for you or should I look into other solutions?

I had it working with this Chrome extension which disables this security feature on the client side, but this is obviously not the solution. :D

jdemaeyer commented 3 years ago

We are purposefully not setting the CORS headers as it'll interfere with out rate-limiting (although currently we are way below request volumes where our rate limits would apply...)

If you still want to make Bright Sky requests from the frontend (opposed to doing them in the backend and then forwarding the data to your frontend), you can try using this service: https://cors-anywhere.herokuapp.com/

It'll simply forward Bright Sky's response with some additional CORS headers. Just replace

const BRIGHTSKY_URL = 'https://api.brightsky.dev/';

with

const BRIGHTSKY_URL = 'https://cors-anywhere.herokuapp.com/https://api.brightsky.dev/';

at the top of the javascript code.

BeyondVertical commented 3 years ago

I understand. Thank you for your help, it works now! :)

jdemaeyer commented 3 years ago

Awesome! :)

jdemaeyer commented 3 years ago

Heyho @BlackScreen!

Bright Sky now allows CORS requests from all origins :)