U
U
uRoot2021-12-18 21:43:34
Backend
uRoot, 2021-12-18 21:43:34

Front and back on localhost. How to share data?

Front: Vue + Axios
Back: Node + Mongo + Express

Back available at URL: localhost:5000
Front running at localhost:8080

Back waiting for request at URL: localhost:5000/api/post/get-all
Making a request from the front:

request screenshot

61be2b1b83a60099392843.png

But in Preview I see an error:
error screen

61be2b5434e8a515966136.png


What am I doing wrong? How to get rid of the error?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Alex Glebov, 2021-12-19
@uroot

Add headers for cors

res.setHeader("Access-Control-Allow-Origin", "*")
  res.setHeader("Access-Control-Allow-Credentials", "true");
  res.setHeader("Access-Control-Allow-Headers", "*");
  res.setHeader("Access-Control-Expose-Headers", "*");
  res.setHeader("Access-Control-Request-Headers", "*");
  res.setHeader( "Access-Control-Allow-Methods", "PUT, POST, GET, DELETE, PATCH, OPTIONS" );

https://developer.mozilla.org/en/docs/Web/HTTP/CORS

R
rPman, 2021-12-18
@rPman

Debugging and logging on the backend
Also, see what kind of headers you are leaving (you can see them in the inspector), maybe you made a mistake and are not sending the expected ones?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question