Basic-MERN-Stack-App icon indicating copy to clipboard operation
Basic-MERN-Stack-App copied to clipboard

Faced issues with API calls during Development

Open BattleOfPlassey opened this issue 4 years ago • 4 comments

To tell the React development server to proxy any unknown requests to your node API server in development, you can add a proxy field to your client package.json, for example:

"proxy": "http://localhost:5000"

which will redirect all traffic to node API and not REACT Development URL.

This way, when you fetch('/api/articles') in development, the development server will recognize that it’s not a static asset, and will proxy your request to http://localhost:5000/api/articles as a fallback.

BattleOfPlassey avatar Oct 18 '20 19:10 BattleOfPlassey

You might face a challenge using http:// instead of https://. Not adding the s to it might cause a problem when calling API.

ogeobubu avatar Dec 10 '20 01:12 ogeobubu

I did try the proxy option then but was not working for me. But works in my new projects. I am happy to assign this issue to you if you are interested to solve :grinning:

hemakshis avatar Jan 08 '21 05:01 hemakshis

Yes thank-you, i will be happy to.

BattleOfPlassey avatar Mar 12 '21 20:03 BattleOfPlassey

@ogeobubu Still got the same error.

Proxy error: Could not proxy request /favicon.ico from localhost:3000 to http://localhost:5000.`

blacksaru avatar Aug 26 '21 09:08 blacksaru