DEV Community

loading...

Discussion on: How to deploy React Application on IIS Server

Collapse
yusuf987 profile image
Yusuf kaleem khan

All worked well but now i am not able to call api via axios or fetch i had add my api main url in package.json in proxy setting .... can you help me what should i do

Collapse
sumitkharche profile image
Sumit Kharche Author • Edited

The proxy feature isn't meant for production. Proxy is most suitable in the Development environment but when you deploy your app with prod mode on a web server then you need to do it in different ways.
Few links for your references:
create-react-app.dev/docs/proxying...
github.com/facebookincubator/creat...

One way you can do it by using the environment variables.
create-react-app.dev/docs/adding-c...

so for development create file .env.development outside of src folder and add your API URL like:

REACT_APP_API_BASE_URL='<your local api url>'

For Production create file .env outside of src folder & add your Prod api base url like above.

once you configure your API URLs you can simply use it in your as App as below:

process.env.REACT_APP_API_BASE_URL

I hope this solves your problem. Please let me know if any queries.