vendredi 22 janvier 2016

Sending a cookie to web browser using Node.js Express

I am following all the suggestions online about how to send a cookie in an HTTP response in Express.

The simple way would be like so:

app.use(function(req,res,next){

  res.cookie('foo', 'bar');

});

however when future requests come to the server from the same web browser, the cookie is not available in req.cookies; in other words, req.cookies['foo'] is undefined.

I have set the front-end code to use "withCredentials" for any AJAX request. Yet the cookie is still not sent to the server, or at least does not appear to be in any way.

One thing that concerns me is that when I call res.cookie('foo','bar') on the server it doesn't show up on the res object/stream as you can see here:

http://ift.tt/1PIr8u8

Is there anything obvious that I am doing wrong?




Aucun commentaire:

Enregistrer un commentaire