Express throws path must be absolute or specify root to res.sendFile when I use react router's redirect in react app bild

Viewed 34

I serve a react-app built version in express, when I login it should redirect and show me another page. However, when I redirect to the right url I got this error path must be absolute or specify root to res.sendFile How can I solve it? Why can't I see other pages other than root? Here is the code in express:

const app = express();
const portApp = 3003;

app.use(cors());
app.use(bodyParser.json());
app.use(
  bodyParser.urlencoded({
    extended: false,
  })
);

app.use(express.static(path.join(__dirname, "build")));
app.use(express.static("public"));

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

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

app.listen(portApp, () => {
  console.log(
    `Attendance list App is listening at http://localhost:${portApp}`
  );
});
0 Answers
Related