Skip to content

Instantly share code, notes, and snippets.

@netroy
Last active August 29, 2015 14:03
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save netroy/b3e1497efa196872d0b0 to your computer and use it in GitHub Desktop.
Save netroy/b3e1497efa196872d0b0 to your computer and use it in GitHub Desktop.
Using encrypted client-sessions with koa
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