Reputation: 1
How can I deploy a js web application that uses an API. I have hosted it on netlify but it doesn't fetch the data.
Everything works fine on localhost. Link: hiuhu-theatre.netlify.app
Upvotes: -1
Views: 240
Reputation: 1328
In firefox you can see the request the function getMovies
made was blocked, the console shows the reason, it links to this URL.
Basically you're trying to use http protocol for that request when you're over https in your website.
To fix that simply change your "http://www.omdbapi.com/” to start with "https://" instead.
Also, if you can, do not add API key to client side code, if you do so anyone can steal it and use it themselves (and that might make you pay more for the service or reach the limit you have really quick), instead do a request to your back-end server so it fetches the data while hiding the API key.
It works in local because you're using http in local aswell.
I've overrided the getMovies
function in my browser to use https
and it worked nicely
Upvotes: 0