express-scaffold
Advanced tools
Comparing version 0.1.7 to 0.1.9
@@ -101,3 +101,4 @@ var matcher = function(id) { | ||
from = (page && page > 1) ? ((page - 1) * limit) : 0, | ||
cursor = self.model.find(params).skip(from).limit(limit), | ||
mainCursor = self.model.find(params).skip(from).limit(limit), | ||
countCursor = self.model.count(params), | ||
pager = { | ||
@@ -108,21 +109,18 @@ limit: limit, | ||
if (this.model) { | ||
self.model.count(params).exec(function(err, count) { | ||
if (!err) { | ||
if (callback && typeof(callback) === 'function') { | ||
if (callback && typeof(callback) === 'function') { | ||
countCursor.exec(function(err, count) { | ||
if (!err) { | ||
pager.max = Math.round(count / limit); | ||
cursor.exec(function(err, results) { | ||
mainCursor.exec(function(err, results) { | ||
callback(err, results, pager); | ||
}); | ||
} | ||
} else { | ||
if (callback && typeof(callback) === 'function') { | ||
callback(err) | ||
} else { | ||
throw err; | ||
callback(err); | ||
} | ||
} | ||
}); | ||
}); | ||
} | ||
} | ||
return { | ||
query: cursor, | ||
query: mainCursor, | ||
count: countCursor, | ||
pager: pager | ||
@@ -129,0 +127,0 @@ }; |
{ | ||
"name": "express-scaffold", | ||
"version": "0.1.7", | ||
"version": "0.1.9", | ||
"description": "a simple but sexy MVC wrapper of Express", | ||
@@ -5,0 +5,0 @@ "logo":"http://ww3.sinaimg.cn/large/61ff0de3jw1e91jmudlz8j201o01o0sj.jpg", |
@@ -11,3 +11,4 @@ var http = require('http'), | ||
json = require('./libs/json'), | ||
middlewares = require('./middlewares/index'); | ||
middlewares = require('./middlewares/index'), | ||
routes = require('./routes/index'); | ||
@@ -27,3 +28,3 @@ var parentPath = function(dir) { | ||
log: ":remote-addr|:date|:method|:url|:status|:res[content-length]|:response-time|\":referrer\"|\":user-agent\"" | ||
} | ||
}; | ||
@@ -65,2 +66,3 @@ var Server = function(configs) { | ||
app.locals.site = params; | ||
app.locals.url = ('production' === app.get('env')) ? params.url : 'http://localhost:' + app.get('port'); | ||
@@ -72,3 +74,2 @@ this.params = params; | ||
this.deps.define('$middlewares', middlewares); | ||
this.deps.define('app', this.app); | ||
@@ -78,10 +79,3 @@ return this; | ||
Server.prototype.routes = function(init) { | ||
// define routes | ||
this.deps.use(init && typeof(init) === 'function' ? init : require('./routes/index')); | ||
// 404 | ||
this.app.get('*', middlewares.error.notfound); | ||
return this; | ||
} | ||
// define models | ||
Server.prototype.models = function(init) { | ||
@@ -95,2 +89,3 @@ var models = require('./models/index'); | ||
// define ctrlers | ||
Server.prototype.ctrlers = function(init) { | ||
@@ -102,2 +97,3 @@ this.deps.define('$Ctrler',require('./ctrlers/index')); | ||
// inject app locals | ||
Server.prototype.locals = function(key, value) { | ||
@@ -108,7 +104,16 @@ if (this.app && key && value) this.app.locals[key] = value; | ||
// define routes | ||
Server.prototype.routes = function(init) { | ||
this.deps.define('app', this.app); | ||
this.deps.use(init && typeof(init) === 'function' ? init : routes); | ||
this.app.get('*', middlewares.error.notfound); | ||
return this; | ||
} | ||
// start instance | ||
Server.prototype.run = function(port) { | ||
if (_.isEmpty(this.app.routes)) this.routes(); | ||
if (port && !isNaN(parseInt(port, 10))) this.app.set('port', parseInt(port, 10)); | ||
this.app.locals.url = (this.app.get('env') === 'production') ? this.params.url : 'http://localhost:' + this.app.get('port'); | ||
http.createServer(this.app).listen(this.app.get('port')); | ||
var app = this.app; | ||
if (_.isEmpty(app.routes)) this.routes(); | ||
if (port && !isNaN(parseInt(port, 10))) app.set('port', parseInt(port, 10)); | ||
http.createServer(app).listen(app.get('port')); | ||
return this; | ||
@@ -115,0 +120,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
316614
1610