I need to use 'CORS' node module in React created using create-react-app utility.
Since its a utility I am not able to tweak inside and inject 'CORS' into pre-configured 'EXPRESS' module.
How can we achieve this?
I need to use 'CORS' node module in React created using create-react-app utility.
Since its a utility I am not able to tweak inside and inject 'CORS' into pre-configured 'EXPRESS' module.
How can we achieve this?
If you are needing this for development and wanting to access an api from your react app but getting an error like this-
then you can get the create-react-app server to proxy your request to your api server quite easily.
create-react-app uses the webpack development server to serve your react app.
So if your react app is being served from
http://localhost:3000
and the api you want to connect to is athttp://localhost:8180/tables
you can simply add aproxy
value into your react app's package.json file like this-then from your react app call your api like
the request will be sent to the create-react-app server which will send it on to the api server and return the results for you.
Full details here Proxying API Requests in Development