Cesar Varela
Cesar Varela

Reputation: 5114

How to use cookies in Azure function HttpTriggers (Node)

I see that there is a 'cookie' key inside the headers property of the request object but nothing else.

I cant find anything related to cookies in the documentation either.

module.exports = function (context, req) {

  context.res = {
    body: "Something"
  };

  // how do I send cookies ??

  context.done();
} 

Upvotes: 1

Views: 2416

Answers (1)

Marie Hoeger
Marie Hoeger

Reputation: 1331

Using Set-Cookie in the headers should work.

Ex:

var exdate = new Date(2018, 5, 1);
context.res = {
    body: "<b> this totally works</b> <i> nice</i>",
    status: 201,
    headers: {
        'Set-Cookie': 'mycookie=test; Expires=' + exdate.toUTCString() + ';'
    }
};
context.done();

Upvotes: 3

Related Questions