Skip to content

Latest commit

 

History

History
53 lines (35 loc) · 1.12 KB

README.md

File metadata and controls

53 lines (35 loc) · 1.12 KB

koa-level

Session storage for koa-generic-session.

Install

$ npm install koa-level

Usage

var koa = require('koa');
var level = require('levelup');
var session = require('koa-sess');
var store = require('koa-level');

var db = level('./db');

var app = koa();
app.use(session({
  store: store({ db: db })
}));

app.use(function*() {
  if(this.url.match(/hello\/\w+/)) {
    this.session.name = this.url.match(/hello\/(\w+)/)[1];
  }
  this.body = 'Hello ' + this.session.name
});

app.listen(3000);

API

store(opts)

Create koa-generic-session compatilbe storage from opts.db.

Complex stuff

If you don't want to pollute the db, use level-sublevel to prefix session ids (you can put data in different "tables").

TTL is only supported, when the underlying db supports it, via level-ttl or similar.

You can use leveldb over the network with multilevel.

License

MIT