Overwrite response status of endpoint in expressjs

  express, javascript

I managed to redirect root '/' to '/users' but '/users' endpoint status overwrites the root endpoint status.

app.get('/', (req, res) => {
  res.redirect(301, '/users');
});

app.get('/users', (req, res) => {
  res.status(200).json(data.filter(user => user.isActive === true));
});

How is it possible to check whether '/users' endpoint is accessed through redirect or not and than set res.status appropriately?

Source: Ask Javascript Questions

LEAVE A COMMENT