Created
December 10, 2014 17:15
-
-
Save jmerrifield/d1774216e43f27ccffd7 to your computer and use it in GitHub Desktop.
Isomorphic cookie module
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var cookie = require('cookie') | |
module.exports.forRequest = function (req) { | |
return { | |
get: function (name) { return req.cookies[name] }, | |
set: function (name, value, options) { | |
req.res.cookie(name, value, options) | |
} | |
} | |
} | |
module.exports.forDocument = function (document) { | |
return { | |
get: function (name) { return cookie.parse(document.cookie)[name] }, | |
set: function (name, value, options) { | |
document.cookie = cookie.serialize(name, value, options) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment