session store

This commit is contained in:
Ritchie Martori
2011-12-19 20:56:27 -08:00
parent 39779ea4d8
commit d113797c1a
6 changed files with 19 additions and 12 deletions

View File

@@ -2,17 +2,20 @@ var express = require('express')
, app = express.createServer()
, db = require('./db').db
, config = require('./config')
, MongoStore = require('connect-mongodb');
, SessionStore = require('./session')(express)
;
// expose the app as a module so everyone can use it
module.exports = app;
app.configure(function(){
app.set('views', __dirname + '/../views');
app.set('view engine', 'ejs');
app.enable('jsonp callback');
app.use(express.bodyParser());
app.use(function(req, res, next) {
var key = 'method'
, method = req.param(key)
@@ -38,13 +41,16 @@ app.configure(function(){
next();
});
app.use(express.cookieParser());
app.use(express.session({
secret: 'secret',
key: 'deployd.sid',
cookie: {httpOnly: false}
// store: new MongoStore({db: db})
cookie: {httpOnly: false},
store: new SessionStore
}));
app.use(app.router);
app.use(express.static(__dirname + '/../public', {redirect: true}));
});

View File

@@ -62,6 +62,8 @@ module.exports = Model.spawn({
, base = (plugin === collection) ? '' : ('/' + plugin)
, route = [base, collection].join('/')
;
console.info(route);
// one model
app.get(route, function(req, res) {

View File

@@ -78,14 +78,17 @@ module.exports = {
remove: ready(function(model) {
collection(db, model, function(err, collection) {
var id = model.get('_id')
var query = model.toQuery() || {}
, id = model.get('_id')
, _id = id;
if(typeof id === 'string') {
_id = ObjectID(id);
}
collection.remove({_id: _id});
_id && (query._id = _id);
collection.remove(query);
model.refresh({_id: null});
});
}),

View File

@@ -62,7 +62,7 @@ function format(msg, method) {
err.name = 'Error';
err.message = arguments[0];
Error.captureStackTrace(err, arguments.callee);
msg = sep('error') + err.stack;
msg = err.stack;
}
// allow for a custom writer

View File

@@ -413,7 +413,6 @@ Model = module.exports = emitter.spawn({
if(err) console.error(err);
});
console.info('Updating', _self.name || _self.collection, json);
}
})
.fetch()
@@ -448,8 +447,6 @@ Model = module.exports = emitter.spawn({
}
;
console.info('Defining routes:', model.name || model.collection);
function handler(req, res, next) {
var query = req.query
, id = req.param('id')
@@ -494,7 +491,7 @@ module.exports.spawn = function(model) {
var instance = spawn.apply(this, arguments)
, cache = instance.isCollection ? _collections : _models;
if(model && model.collection && !cache[instance.collection]) {
if(model && !model.setup && model.collection && !cache[instance.collection]) {
cache[instance.collection] = instance;
instance.updateSettings();
instance.defineRoutes(app);

View File

@@ -14,8 +14,7 @@
"express": ">= 2.0.0",
"underscore": ">= 1.0.0",
"mongodb": ">= 0.9.0",
"ejs": ">= 0.4.3",
"connect-mongodb": ">= 1.0.0"
"ejs": ">= 0.4.3"
},
"bin":{
"deployd":"./bin/deployd"