Last active
August 29, 2015 14:03
-
-
Save netroy/b3e1497efa196872d0b0 to your computer and use it in GitHub Desktop.
Using encrypted client-sessions with koa
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 koa = require('koa'); | |
var sessions = require("client-sessions"); | |
var app = koa(); | |
var middleware = sessions({ | |
cookieName: '_xyz', | |
secret: 'blah', | |
duration: 2400000 | |
}); | |
app.use(function *(next) { | |
var context = this; | |
var req = context.request.req; | |
var res = context.response.res; | |
yield middleware.bind(null, req, res); | |
Object.defineProperty(context, 'session', { | |
get: function () { return req.session; } | |
}); | |
yield next; | |
}); | |
app.listen(9999); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment