0

I am developing a MERN stack app. I am using the http-proxy-middleware package for proxying API requests. At the client side, inside "src" folder, I have a file called setupProxy.js. And the code inside is as follows:

const { createProxyMiddleware } = require("http-proxy-middleware");

module.exports = function (app) {
  app.use(
    "/api/products",
    createProxyMiddleware({
      target: "http://localhost:8000",
    })
  );
};

As you can see, I am making a request to "/api/products".

But I am receiving error in the console. The error says:

[HPM] Error occurred while trying to proxy request /api/products from localhost:3000 to http://localhost:8000 (ECONNREFUSED) (https://nodejs.org/api/errors.html#errors_common_system_errors)

Also, the request is being made to "http://localhost:3000/api/products".

How can I solve this issue?

lissettdm
  • 12,267
  • 1
  • 18
  • 39
HKS
  • 526
  • 8
  • 32
  • @LoolKovsky Can you please elaborate. – HKS Jan 31 '21 at 05:43
  • you didn't post the code on the server-side. neither the one from the frontend where you call the endpoint. It is indicated to post a minimum reproducible example so that we can help you – LoolKovsky Feb 01 '21 at 17:13

0 Answers0