Skip to content

purposeindustries/koa-level

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

LevelDB session storage for Koa

Resources

License

Stars

Watchers

Forks

Packages

No packages published