refactoring boot logic
Before adoption: this commit came in with the history the project adopted, so no landing records it.
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parent 371b381 · Browse files · 1 file·+36 added−25 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
1 file+36 added−25 removed
- other:+36 added−25 removed
Provenance
- Commit
8848004- Tree
76de5d8- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
371b381
1 file changed+36 added−25 removed
modified:lib/application.js+36 added-25 removed
29 unmodified lines30 31 /**32 * Initialize the server.33 *34- * @param {Array} middleware34+ * - setup default configuration35+ * - setup default middleware36+ * - setup route reflection methods37+ *38 * @api private39 */40 38-app.init = function(middleware){41+app.init = function(){42 var self = this;43 this.cache = {};44 this.settings = {};45 this.engines = {};46 this.redirects = {};47 this.isCallbacks = {};48+ this.defaultConfiguration();49 50+ // route manipulation methods51+ methods.forEach(function(method){52+ self.lookup[method] = function(path){53+ return self.routes.lookup(method, path);54+ };55+56+ self.match[method] = function(path){57+ return self.routes.match(method, path);58+ };59+60+ self.remove[method] = function(path){61+ return self.routes.lookup(method, path).remove();62+ };63+ });64+65+ // del -> delete66+ self.lookup.del = self.lookup.delete;67+ self.match.del = self.match.delete;68+ self.remove.del = self.remove.delete;69+};70+71+/**72+ * Initialize application configuration.73+ *74+ * @api private75+ */76+77+app.defaultConfiguration = function(){78+ var self = this;79+80 // default settings81 this.set('home', '/');82 this.set('env', process.env.NODE_ENV || 'development');83 46 unmodified lines130 131 next();132 });133 100- // apply middleware101- if (middleware) middleware.forEach(self.use.bind(self));102-134 // router135 this.routes = new Router(this);136 this.__defineGetter__('router', function(){137 this.__usedRouter = true;6 unmodified lines144 // default production configuration145 this.configure('production', function(){146 this.enable('view cache');147 });117-118- // route manipulation methods119- methods.forEach(function(method){120- self.lookup[method] = function(path){121- return self.routes.lookup(method, path);122- };123-124- self.match[method] = function(path){125- return self.routes.match(method, path);126- };127-128- self.remove[method] = function(path){129- return self.routes.lookup(method, path).remove();130- };131- });132-133- // del -> delete134- self.lookup.del = self.lookup.delete;135- self.match.del = self.match.delete;136- self.remove.del = self.remove.delete;148 };149 150 /**151 * Remove routes matching the given `path`.465 unmodified lines