Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

MongoDB backed session middleware for Koa

License

NotificationsYou must be signed in to change notification settings

aheckmann/koa-session-mongodb

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

3 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

MongoDB backed session middleware for Koa.js

Unstable

This module currently suffers from a memory leak due to its reliance on theobserved module. You probably want to usethis module instead while we wait for v8 to fix thememory leak.

Installation

$npminstallkoa-session-mongodb

Example

View counter example:

varsession=require('koa-session-mongodb');varmongo=require('mongodb').MongoClient;varkoa=require('koa');mongo.connect(uri,function(err,db){if(err)throwerr;varapp=koa();app.keys=['some secret'];app.use(session({collection:db.collection('session')}));app.use(function*(){varn=this.session.views||0;this.session.views=++n;this.body=n+' views';})app.listen(3000);console.log('listening on port 3000');})

Semantics

This module provides "guest" sessions, meaning any visitor will have a session,authenticated or not. If a session isnew a Set-Cookie will be produced regardlessof populating the session.

API

Options

The cookie name is controlled by thekey option, which defaultsto "sid". All other options are passed toctx.cookies.get() andctx.cookies.set() allowing you to control security, domain, path,and signing among other settings.

Session#isNew

Returnstrue if the session is new.

Destroying a session

To destroy a session simply set it tonull:

this.session=null;

License

MIT

About

MongoDB backed session middleware for Koa

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

[8]ページ先頭

©2009-2025 Movatter.jp