React build and backend Express.js

Viewed 36

I am developing an application using React and Express.js. I define static in React and build my back end using the code below, but when I make a get request, the following error is displayed in the client console. What can I do?

app.get("*", (req, res, next) => {
  res.sendFile(path.join(__dirname, "build", "../../build/index.html"));
});

// Backend API router

app.use("/api", router);

Client-side error message

Enter image description here

1 Answers

You should consider deploying React code using nginx, and do a port forwarding within nginx to the backend APIs.

Related