I
I
Incold2020-10-03 01:44:00
CORS
Incold, 2020-10-03 01:44:00

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'
            }
        }
    }
}


Request:
axios.get(API.baseUrl + '/top-headlines', API.config)
            .then(res => ...)
            .catch(()=> ...)


Disabling cors with a Chrome extension doesn't help either. Tell me, are there any options to solve this error, given that I do not have access to the server to which I am sending the request?

PS Please, there is no need to describe what cors is and how it works, I'm only interested in solutions to the problem.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
G
granty, 2020-10-03
@granty

solve this error, given that I only work with the front?

If this could be done on the frontend, then all CORS would be down the drain.
no need to describe what cors is and how it works, I'm only interested in solutions to the problem.

Once you know "how it works" - you know the options for solving the problem of cross-domain requests .

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question