* @api public
*/
function Application(middleware){
this.config = [];
this.config = {};
this.settings = {};
this.routes = { get: [], post: [], put: [], del: []};
connect.Server.call(this, (middleware || []).concat([
{ provider: 'rest', routes: this.routes }
sys.inherits(Application, connect.Server);
/**
* Listen on the given port after running configuration blocks.
*
* @param {Number} port
* @api public
*/
Application.prototype.listen = function(port){
this.runConfig('any', 'development');
connect.Server.prototype.listen.call(this, port);
};
/**
* Run config callbacks for the given environment(s);
*
* @param {String} env ...
* @return {Application}
* @api public
*/
Application.prototype.runConfig = function(){
for (var i = 0, len = arguments.length; i < len; ++i) {
var env = arguments[i];
if (env in this.config) {
var config = this.config[env];
config.forEach(function(fn){
fn.call(this);
}, this);
}
}
return this;
};
/**
* Assign setting a value
*
* @param {String} setting
* @param {String} val
Application.prototype.disable = function(setting){
return this.set(setting, false);
};
/**
* Disable setting.
*
* @param {String} setting
* @return {Application}
* @api public
*/
Application.prototype.configure = function(env, fn){
if (typeof env === 'function') fn = env, env = 'any';
(this.config[env] = this.config[env] || []).push(fn);
};
// Generate RESTful methods
(function(method){
Application.prototype[method] = function(path, fn){