M
M
Maxim_12019-08-11 18:13:11
JavaScript
Maxim_1, 2019-08-11 18:13:11

How to remove title from OPTIONS?

Hello everyone, when sending a request to another site, an error appears in the console:

Access to fetch at ' https://min-api.cryptocompare.com/data/price?fsym=... ' from origin ' localhost:3000 ' has been blocked by CORS policy: Request header field x-compress is not allowed by Access-Control-Allow-Headers in preflight response.

If I understand correctly, the browser sends the "x-compress" header in options to the server, and the server replies that it does not accept such headers. Everything would be fine, but the program worked for a long time, hence the misunderstanding of what is happening.
I make a request from a React application using fetch.
refreshFetch = async (url) => {
  try {
    return await (await fetch(url)).json();
  } catch (e) {
    throw Error('Ошибка');
  }
};
Thank you!

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
yablokoff, 2019-08-11
@yablokoff

Ran into the same issue, seems only relevant for chrome on mac.
It arose literally yesterday, until I found no solutions, except to add a field in response to Options on the backend.

M
Mikhail Ivanov, 2019-08-12
@Mishany

Good afternoon!
You can add x-compress to the header, maybe this will help you:

app.use("/", (req, res, next) => {
/* */
 res.setHeader("Access-Control-Allow-Headers", "accept, authorization, content-type, x-compress");
/* */
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question