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`,
}
لم تجد الفلم أو المسلسل ؟ سجل دخولك و انشئها
هل تريد تقييم او اضافة هذا العنصر للقائمة؟
لست عضو؟
رد بواسطة Travis Bell
بتاريخ سبتمبر 7, 2020 في 11:37 صباحا
First off, I am not familiar with Axios, so I can only assume a few things based on what you posted here. It looks like Axios is treating your base URL as a resolvable URL for some type of a preflight request. But if you go to
https://api.themoviedb.org/3
, you'll see that it's not a resolvable URL (nothing exists there).Soooo... as a temporary thing to try, don't use
baseURL
. AnOPTIONS
call to any of the actual methods, returns the correct headers, example:Request
Response
Creating a new resolvable URL at
https://api.themoviedb.org/3
is certainly doable, but it does not exist right now.رد بواسطة d2O
بتاريخ أكتوبر 17, 2020 في 2:51 صباحا
Hi there,
I'm facing with the same issue. If I make a request browser return me CORS problem. I've tried to used heroku cors everywhere but without success.
There is another workaround or you can solve this step?
thanks
رد بواسطة kausarshaikh
بتاريخ أكتوبر 18, 2020 في 7:29 صباحا
I'm facing similar issue, and looking at the code, looks like you too are following the Clever Programmer tutorial for Netflix clone. Please let me know what worked for you.
رد بواسطة rafidah
بتاريخ نوفمبر 5, 2020 في 3:42 صباحا
رد بواسطة xRoxsan
بتاريخ نوفمبر 27, 2020 في 12:40 مساءا
Im following clever programmer and im having the same issue
رد بواسطة shanky31
بتاريخ ديسمبر 6, 2020 في 10:16 صباحا
I'm facing the same issue as well.
رد بواسطة ticao2 🇧🇷 pt-BR
بتاريخ ديسمبر 6, 2020 في 10:57 صباحا
If the explanation given by Travis Bell did not solve or help, then perhaps one of these conversations can help. Perhaps.
CORS issue
In case you have not researched here in the Forum, below the link of 2 posts with similar problem.
Maybe it helps:
https://www.themoviedb.org/talk/5f621eae93388b003864513c
https://www.themoviedb.org/talk/5eb07271a13533001b72740a
رد بواسطة sebazagra
بتاريخ ديسمبر 6, 2020 في 4:41 مساءا
axios is properly working for me, using it client side. Here's an example of my code
رد بواسطة zaferozcan
بتاريخ ديسمبر 29, 2020 في 12:53 مساءا
replace your axios.js file with this
رد بواسطة darkfaze
بتاريخ يناير 21, 2021 في 1:37 صباحا
Hello did anyone find a solution I am getting the same error too
رد بواسطة darkfaze
بتاريخ يناير 21, 2021 في 1:39 صباحا
I tried this but still I am getting the same error
رد بواسطة codebyshami
بتاريخ يناير 25, 2021 في 7:01 صباحا
you find any solution yet ?
رد بواسطة PrawinPravs
بتاريخ فبراير 27, 2021 في 11:07 صباحا
Hey guys I'm also facing the same issue and the clover programmmmmmer didn't say properly that they may have missed out something which we don't know.
رد بواسطة PrawinPravs
بتاريخ فبراير 27, 2021 في 12:40 مساءا
Really it works so well i got it ..
Before going to execute the code you should have to disable the CORS issue by running the commends
رد بواسطة fayad-2021
بتاريخ مارس 5, 2021 في 10:21 صباحا
how this working with you i am doing same this code and not working for me