0

My backend runs on localhost:5000 and my frontend on localhost:3000. The proxy I declared in package.json suddenly stopped working today. I fetch using axios in frontend like this:

axios.get('/api/posts')
  .then(function (response) {
    console.log(response);
  })
  .catch(function (error) {
    // handle error
    console.log(error);
  })

It fetches from localhost:3000 instead of localhost:5000 even though I have included the proxy in package.json:

{ "proxy": "http://localhost:5000" }

I've tested on other projects too.

VLAZ
  • 26,331
  • 9
  • 49
  • 67
Hashem Mashem
  • 317
  • 1
  • 5
  • 11
  • Does this answer your question? https://stackoverflow.com/a/67335451/4025157 – MC Naveen Feb 17 '22 at 19:14
  • @MCNaveen Tried everything on StackOverflow, still not working. – Hashem Mashem Feb 17 '22 at 19:31
  • Looks like http-proxy-middleware could solve your issue. Did you updated the dependencies recently? Do you see any error in the console? Is your backend script running correctly? – MC Naveen Feb 17 '22 at 19:35
  • @MCNaveen When using the http-proxy-middleware, my client doesn't open in localhost:3000 anymore. I use it like this (src/setupProxy.js): ```const proxy = require("http-proxy-middleware"); module.exports = function (app) { app.use(proxy("/api", { target: "http://localhost:5000/" })); }; ``` – Hashem Mashem Feb 17 '22 at 19:47

0 Answers0