refactored http.js
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 393d38f · Browse files · 1 file·+35 added−23 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+35 added−23 removed
- other:+35 added−23 removed
Provenance
- Commit
a3678cd- Tree
2eef675- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
393d38f
1 file changed+35 added−23 removed
modified:lib/http.js+35 added-23 removed
16 unmodified lines17 , url = require('url')18 , utils = connect.utils;19 20 /**21+ * Expose `HTTPServer`.22+ */23+24+exports = module.exports = HTTPServer;25+26+/**27+ * Server proto.28+ */29+30+var app = HTTPServer.prototype;31+32+/**33 * Initialize a new `HTTPServer` with optional `middleware`.34 *35 * @param {Array} middleware36 * @api public37 */38 27-var Server = exports = module.exports = function HTTPServer(middleware){39+function HTTPServer(middleware){40 connect.HTTPServer.call(this, []);41 this.init(middleware);42 };43 44 /**45 * Inherit from `connect.HTTPServer`.46 */47 36-Server.prototype.__proto__ = connect.HTTPServer.prototype;48+app.__proto__ = connect.HTTPServer.prototype;49 50 /**51 * Initialize the server.52 *53 * @param {Array} middleware54 * @api private55 */56 45-Server.prototype.init = function(middleware){57+app.init = function(middleware){58 var self = this;59 this.cache = {};60 this.match = {};61 this.lookup = {};75 unmodified lines137 /**138 * When using the vhost() middleware register error handlers.139 */140 129-Server.prototype.onvhost = function(){141+app.onvhost = function(){142 this.registerErrorHandlers();143 };144 145 /**2 unmodified lines148 * @return {Server} for chaining149 * @api public150 */151 140-Server.prototype.registerErrorHandlers = function(){152+app.registerErrorHandlers = function(){153 this.errorHandlers.forEach(function(fn){154 this.use(function(err, req, res, next){155 fn.apply(this, arguments);156 });10 unmodified lines167 * @return {Server} for chaining168 * @api public169 */170 159-Server.prototype.use = function(route, middleware){171+app.use = function(route, middleware){172 var app, home, handle;173 174 if ('string' != typeof route) {175 middleware = route, route = '/';49 unmodified lines225 * @return {Server} for chaining226 * @api public227 */228 217-Server.prototype.mounted = function(fn){229+app.mounted = function(fn){230 this.__mounted = fn;231 return this;232 };233 3 unmodified lines237 * @return {Server} for chaining238 * @api public239 */240 229-Server.prototype.register = function(){241+app.register = function(){242 view.register.apply(this, arguments);243 return this;244 };245 5 unmodified lines251 * @return {Server} for chaining252 * @api public253 */254 243-Server.prototype.helpers =244-Server.prototype.locals = function(obj){255+app.helpers =256+app.locals = function(obj){257 utils.merge(this._locals, obj);258 return this;259 };260 5 unmodified lines266 * @return {Server} for chaining267 * @api public268 */269 258-Server.prototype.dynamicHelpers = function(obj){270+app.dynamicHelpers = function(obj){271 utils.merge(this.dynamicViewHelpers, obj);272 return this;273 };274 39 unmodified lines314 * @return {Server} for chaining315 * @api public316 */317 306-Server.prototype.param = function(name, fn){318+app.param = function(name, fn){319 if (Array.isArray(name)) {320 name.forEach(function(name){321 this.param(name, fn);322 }, this);12 unmodified lines335 * @return {Server} for chaining336 * @api public337 */338 327-Server.prototype.error = function(fn){339+app.error = function(fn){340 this.errorHandlers.push(fn);341 return this;342 };343 5 unmodified lines349 * @return {Server} for chaining350 * @api public351 */352 341-Server.prototype.is = function(type, fn){353+app.is = function(type, fn){354 if (!fn) return this.isCallbacks[type];355 this.isCallbacks[type] = fn;356 return this;357 };7 unmodified lines365 * @return {Server|Mixed} for chaining, or the setting value366 * @api public367 */368 357-Server.prototype.set = function(setting, val){369+app.set = function(setting, val){370 if (val === undefined) {371 if (this.settings.hasOwnProperty(setting)) {372 return this.settings[setting];373 } else if (this.parent) {12 unmodified lines386 * @return {Boolean}387 * @api public388 */389 378-Server.prototype.enabled = function(setting){390+app.enabled = function(setting){391 return !!this.set(setting);392 };393 394 /**3 unmodified lines398 * @return {Boolean}399 * @api public400 */401 390-Server.prototype.disabled = function(setting){402+app.disabled = function(setting){403 return !this.set(setting);404 };405 406 /**3 unmodified lines410 * @return {Server} for chaining411 * @api public412 */413 402-Server.prototype.enable = function(setting){414+app.enable = function(setting){415 return this.set(setting, true);416 };417 418 /**3 unmodified lines422 * @return {Server} for chaining423 * @api public424 */425 414-Server.prototype.disable = function(setting){426+app.disable = function(setting){427 return this.set(setting, false);428 };429 430 /**4 unmodified lines435 * @return {Server} for chaining436 * @api public437 */438 427-Server.prototype.redirect = function(key, url){439+app.redirect = function(key, url){440 this.redirects[key] = url;441 return this;442 };443 5 unmodified lines449 * @return {Server} for chaining450 * @api public451 */452 441-Server.prototype.configure = function(env, fn){453+app.configure = function(env, fn){454 if ('function' == typeof env) {455 fn = env, env = 'all';456 }457 if ('all' == env || env == this.settings.env) {4 unmodified lines462 463 // Generate routing methods464 465 function generateMethod(method){454- Server.prototype[method] = function(path){466+ app[method] = function(path){467 var self = this;468 469 // Lookup470 if (1 == arguments.length) {15 unmodified lines486 methods.forEach(generateMethod);487 488 // Alias delete as "del"489 478-Server.prototype.del = Server.prototype.delete;490+app.del = app.delete;