Proxy is not working in package.json


Proxy is not working in package.json
I have a Node server at localhost:9001 and a React webapp (create-react-app
). I need /auth/signin
request go against server, so in the React app package.json
, I have configured a proxy like this:
create-react-app
/auth/signin
package.json
"proxy":
"/auth":
"target": "http://localhost:9001"
When user click login button, I make a POST request with axios against that endpoint (I'm using async/await):
const axios = require('axios');
const response = await axios.post('/auth/signin', email, password );
But I see in browser I'm getting bad response:
[Error] Failed to load resource: the server responded with a status of
400 (Bad Request) (signin, line 0) http://localhost:3000/auth/signin
As you see, request is against http://localhost:3000/auth/signin instead of http://localhost:9001/auth/signin (bad port). Proxy defined in package.json
is being ignored.
package.json
What am I missing? I've also tried with fetch
instead of axios
, and including Accept application/json
header.
fetch
axios
Accept application/json
Server is running properly and same request is working fine from Postman.
proxy
package.json
Yes, several times
– Héctor
1 min ago
By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.
Have you restarted the dev server after you added the
proxy
field inpackage.json
?– Tholle
5 mins ago