diff --git a/lib/app.js b/lib/app.js index 1f291c9..a7a447a 100644 --- a/lib/app.js +++ b/lib/app.js @@ -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})); }); diff --git a/lib/collection.js b/lib/collection.js index 39f96c1..7342a84 100644 --- a/lib/collection.js +++ b/lib/collection.js @@ -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) { diff --git a/lib/db.js b/lib/db.js index f2c9579..515084f 100644 --- a/lib/db.js +++ b/lib/db.js @@ -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}); }); }), diff --git a/lib/log.js b/lib/log.js index 741518a..5334bb1 100644 --- a/lib/log.js +++ b/lib/log.js @@ -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 diff --git a/lib/model.js b/lib/model.js index c117063..e41b52c 100644 --- a/lib/model.js +++ b/lib/model.js @@ -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); diff --git a/package.json b/package.json index 7cc2ae3..98124de 100644 --- a/package.json +++ b/package.json @@ -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"