mirror of
https://github.com/zhigang1992/deployd.git
synced 2026-05-22 20:37:59 +08:00
session store
This commit is contained in:
12
lib/app.js
12
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}));
|
||||
});
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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});
|
||||
});
|
||||
}),
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user