D
D
Dmitry Vorobyov2021-02-10 20:22:42
Node.js
Dmitry Vorobyov, 2021-02-10 20:22:42

How to create a local server for project testing from Create React App?

I ran into such a problem, I'm learning react, I want my project from the Create React App environment to send GET, POST requests, etc. to a local server, such as OpenServer, and receive responses from it. I use the axios library to generate requests.
So, I created a host on OpenServer, posted a JSON file that comes as a response to a GET request. I checked POSTMAN, everything is OK, the object comes from the file that is needed. But when trying to get a response to a request via axios, it gives an error Access to XMLHttpRequest at ' webserver/db.json ' from origin ' localhost:3000' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource. As I understand it, the browser (I use Yandex) or OpenServer are prohibited from sending / receiving requests from one local server to another 602415a57105d992554105.png
. I tried to create it separately using the json-server library in Node.js, but when I started it, the server from react create app crashed, and turnover

Answer the question

In order to leave comments, you need to log in

2 answer(s)
J
Just Me, 2021-02-11
@CriticalError

to do this, run express with cors

L
lmx, 2021-02-10
@lmx

Hello, in your case, you have a CORS error, google for keywords. "open server cors".
And in general, study the question of what CORS is and why it is needed.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question