A
A
Albert2021-07-13 19:22:10
CORS
Albert, 2021-07-13 19:22:10

Is it possible to run backend and frontend on the same machine without cors error?

Good afternoon!
Faced such a problem.
There is a ready-made backend that runs on localhost:3000.
The task is to prepare a React frontend that will query and display data from the backend.
Since the front is running on a different localhost, the fetch request raises corsError no 'access-control-allow-origin'.
Is there any way to solve this problem without editing the backend?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
M
maxluks, 2021-07-13
@maxluks

Alternatively, you can use proxy in package.json
Proxying API Requests in Development

M
Max, 2021-07-13
@mbelskiy

In addition to webpack, there is an option to make a proxy on nginx. config snippet:

location /api/ {
  # …
  proxy_hide_header Access-Control-Allow-Origin;
  add_header Access-Control-Allow-Origin * always;
}

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question