-
-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
27 lines (26 loc) · 789 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
const Cookie = require('./cookie');
/**
* [function cookie]
* @param {[type]} req [request]
* @param {[type]} res [response]
* @param {Function} next [call next middleware]
*/
function cookie(req, res, next){
// cookie getter
req.cookies = Cookie.parse(req.headers['cookie']);
/**
* [function cookie setter]
* @param {[type]} key [description]
* @param {[type]} value [description]
* @param {[type]} attrs [description]
* @return {[type]} [description]
*/
res.cookie = function(key, value, attrs = {}){
if(value === null) { attrs.expires = new Date(0); value = ''; }
res.setHeader('Set-Cookie', Cookie(key, value, attrs).toHeader());
};
next();
};
cookie.Cookie = Cookie;
cookie.parse = Cookie.parse;
module.exports = cookie;