Hiuhu
Hiuhu

Reputation: 1

How to deploy a js web app that fetches data from an api

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

Answers (1)

Gunther
Gunther

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

Related Questions