Search code examples
axiosgetfrontendmern

how to use proxy for axios


im writing webapp and my frontend is running on

http://localhost:3000

and backend is running on

http://localhost:4000

i want use axios to do a get request on this url "http://localhost:4000/api/v1/products"

so i make a proxy in package.json file like this

"proxy": "http://127.0.0.1:4000"

and i did a get requset like this

const { data } = await axios.get("/api/v1/products")

but axios is ignore the proxy and requesting above get request from "localhost:3000" as show here

how can i do a get request from "localhost:4000" this url insted of "localhost:3000" ?


Solution

  • it seems you add your proxy in the wrong file please check the proxy should add to the package.json file that belongs to your react app