I'm getting a CORS error when using 'JSON Server'. How can I fix it?

Question

Grade: Education Subject: Support
I'm getting a CORS error when using 'JSON Server'. How can I fix it?
Asked by:
68 Viewed 68 Answers

Answer (68)

Best Answer
(305)
CORS errors occur when your client-side application (e.g., a React app) is making requests to a different origin than the 'JSON Server'. Use the `--cors` flag when starting `json-server`: `json-server --cors db.json`. This enables CORS and allows requests from any origin (for development purposes only).