0

I'have dockerized a react app with mongodb but when I try to fetch users data I get the following error:

project-ui-1     |
project-ui-1     | Proxy error: Could not proxy request /loadUsers from localhost:3000 to http://localhost:5000.
project-ui-1     | See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
project-ui-1     |
project-ui-1     | Proxy error: Could not proxy request /loadUsers from localhost:3000 to http://localhost:5000.
project-ui-1     | See https://nodejs.org/api/errors.html#errors_common_system_errors for more information (ECONNREFUSED).
project-ui-1     |

But when I type to my browser localhost/5000/loadUsers it is running fine. I use the following fetch request:

const loadUsers = async () => {
  const newData = await fetch("/loadUsers", {
    method: "GET",
    headers: {
      "Content-Type": "application/json",
      Accept: "application/json",
    },
  }).then((res) => res.json());
  return newData.data;
};

And the serverside code is:


app.get("/loadUsers", async (req, res) => {
  const result = await Db.getUsers();
  res.send(result);
});

0 Answers0