Last active
December 17, 2015 08:39
-
-
Save jpillora/5582065 to your computer and use it in GitHub Desktop.
Express/Connect Session Store Template
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
// http://www.senchalabs.org/connect/middleware-session.html | |
// Use with express like so: | |
// | |
// app.use(express.session({ | |
// store: new MyStore(), | |
// secret: 'secret' | |
// })); | |
var connect = require('connect'); | |
//Base Store Class | |
var Store = connect.session.Store; | |
//Constructor | |
function MyStore(options) { | |
var self = this; | |
options = options || {}; | |
Store.call(this, options); | |
} | |
//Inherit Base Store Class | |
MyStore.prototype.__proto__ = Store.prototype; | |
//Get. session id, callback(err,obj) | |
MyStore.prototype.get = function(sid, fn) { | |
console.log("get", sid); | |
fn(null, {}); | |
}; | |
//Set. session id, session object, callback(err) | |
MyStore.prototype.set = function(sid, sess, fn) { | |
console.log("set", sid, sess); | |
fn(null); | |
}; | |
//Delete. session id, callback(err) | |
MyStore.prototype.destroy = function(sid, fn) { | |
console.log("del", sid); | |
fn(null); | |
}; | |
module.exports = MyStore; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment