0

I need to redirect users from URLs like /?v=xxx to the index without parameters while passing these parameters in some other way to actually use them internally (so I just want to remove the parameters from the address).

The first idea I came up with was the usage of custom headers:

app.get('/', function(req, res) {
  if (req.query.v !== undefined) {
    res.set('Video-ID', req.query.v);
    res.redirect('/');
  } else {
    console.log(req.get('Video-ID'));
    res.render('index', {
      videoID: req.get('Video-ID')
    });
  }
});

but it seems that it doesn't work -- console.log(req.get('Video-ID')); prints undefined every time.

Is there any way to redirect user while passing arguments internally without using cookies? If I have to use cookies, what is the best way to do it in Express 4 then?

Jeremy
  • 1
  • 85
  • 340
  • 366
FrozenHeart
  • 19,844
  • 33
  • 126
  • 242

1 Answers1

1

You won't be able to achieve this.

cookie-parser is a great tool. Though, you can use Express's cookies and they will do what you need.

// Before redirect
res.cookie('videoId', '123456789');
// After redirect method
res.clearCookie('videoId');
Andrius
  • 5,934
  • 20
  • 28