Answer the question
In order to leave comments, you need to log in
Why am I getting a CORS error when working with Newsapi?
I ran into a problem when working with newsapi ( https://newsapi.org/docs ), everything works fine on the locale, but after deploying to firebase, I started getting an error:
"Access to XMLHttpRequest at ' https://newsapi.org/v2 /top-headlines?country=en ' from origin ' https://amigoweb-tt.web.app ' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: It does not have HTTP ok status ."
Request config:
export const API = {
baseUrl: 'https://newsapi.org/v2',
apiKey: 'API_KEY',
get config() {
return {
headers: {
'X-Api-Key': this.apiKey
},
params: {
country: 'ru'
}
}
}
}
axios.get(API.baseUrl + '/top-headlines', API.config)
.then(res => ...)
.catch(()=> ...)
Answer the question
In order to leave comments, you need to log in
solve this error, given that I only work with the front?
no need to describe what cors is and how it works, I'm only interested in solutions to the problem.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question