Hello I'm getting this CORS error and can't figure out how to overcome this:
Access to XMLHttpRequest at 'https://api.themoviedb.org/3' from origin 'http://localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.
xhr.js:184 GET https://api.themoviedb.org/3 net::ERR_FAILED
This is my request code:
async function fetchData(){
const response = await axios.get(requests.selectedOption);
console.log(response);
setMovies(response.data.results);
return response;
}
and this is config 1:
import axios from 'axios';
const instance = axios.create({
baseURL: 'https://api.themoviedb.org/3',
});
export default instance;
and this is config 2:
const API_KEY = here goes my api key;
export default {
fetchTrending: `/trending/all/week?api_key=${API_KEY}&language=en-US`,
fetchTopRated: `/movie/top_rated?api_key=${API_KEY}&language=en-US`,
fetchActionMovies: `/discover/movie?api_key=${API_KEY}&with_genres=28`,
fetchComedyMovies: `/discover/movie?api_key=${API_KEY}&with_genres=35`,
fetchHorrorMovies: `/discover/movie?api_key=${API_KEY}&with_genres=27`,
fetchRomanceMovies: `/discover/movie?api_key=${API_KEY}&with_genres=10749`,
fetchMystery: `/discover/movie?api_key=${API_KEY}&with_genres=9648`,
fetchSciFi: `/discover/movie?api_key=${API_KEY}&with_genres=878`,
fetchWestern: `/discover/movie?api_key=${API_KEY}&with_genres=37`,
fetchAnimation: `/discover/movie?api_key=${API_KEY}&with_genres=16`,
fetchTV: `/discover/movie?api_key=${API_KEY}&with_genres=10770`,
}
Can't find a movie or TV show? Login to create it.
Want to rate or add this item to a list?
Not a member?
Reply by fayad-2021
on March 5, 2021 at 10:33 AM
I have same issue pleas if anyone know the the way how to fix the cors same issue and the clover programmmmmmer
Reply by PrawinPravs
on March 5, 2021 at 10:59 AM
You have to disable the CORS first.
Reply by PrawinPravs
on March 5, 2021 at 11:00 AM
yes first do disable the cors dude then you can see the http request
Reply by PrawinPravs
on March 5, 2021 at 11:09 AM
https://chrome.google.com/webstore/detail/allow-cors-access-control/lhobafahddgcelffkeicbaginigeejlf/related?hl=en
Reply by PrawinPravs
on March 5, 2021 at 11:12 AM
Even you can use this command and run the command chromium-browser --disable-web-security --user-data-dir="[some directory here]" you will get a warning ignore it and run your localhost:300 in to that page and you can fetch the data from TMDB cool don't forget to replay if your problem get solved..
Reply by ccamiletti
on March 5, 2021 at 12:17 PM
this is not an error about the api. you get this error basically because it is a different domain than your page is on. you can implement a "reverse proxy" with Nginx for example.
Reply by PrawinPravs
on March 5, 2021 at 12:54 PM
Whatever i said till now you just follow it because ನ್ was also facing the same issue by seeing that clover prgmmr but finally i have done deployment also
Reply by leggasick_vincent
on March 9, 2021 at 4:32 PM
Chrome extension for cors This will fix the problem.
Reply by adamfadly
on March 10, 2021 at 5:54 AM
same problem i had, still don't know what's wrong
Reply by Reactingreactnetflix
on March 16, 2021 at 6:37 PM
@PrawinPravs hey dude the error is gone but it is still not returning the object
Reply by aves__rastogi
on May 11, 2021 at 4:58 AM
Didn't work for me either. Anybody got the solution? Following the netflix clone tutorial by qazi.
Reply by covfefe101-vik
on June 25, 2021 at 11:11 AM
What do you mean "by running the commends"?
Reply by Enzeakor
on August 15, 2021 at 9:47 PM
Hi Devs This worked for me
Instead of having the baseUrl in axios.js. let it be in the above format so axios.js doesnt exist. Note: when calling axios make sure you import it globally. Hope this helps you to
Reply by mosmmy
on November 30, 2021 at 4:04 AM
thanks problem is solved
Reply by akhilatadi
on January 4, 2022 at 2:34 PM
hey try adding this at the end of requests.js
"export default requests; "
worked for me