Skip to content

Instantly share code, notes, and snippets.

@jmerrifield
Created December 10, 2014 17:15
Show Gist options
  • Save jmerrifield/d1774216e43f27ccffd7 to your computer and use it in GitHub Desktop.
Save jmerrifield/d1774216e43f27ccffd7 to your computer and use it in GitHub Desktop.
Isomorphic cookie module
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