Skip to content
Myr

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

1 file+35 added−23 removed

modified:lib/http.js+35 added-23 removed
16 unmodified lines
17 , url = require('url')18 , utils = connect.utils;1920/**21 * Expose `HTTPServer`.22 */2324exports = module.exports = HTTPServer;2526/**27 * Server proto.28 */2930var app = HTTPServer.prototype;3132/**33 * Initialize a new `HTTPServer` with optional `middleware`.34 *35 * @param {Array} middleware36 * @api public37 */3827var Server = exports = module.exports = function HTTPServer(middleware){39function HTTPServer(middleware){40 connect.HTTPServer.call(this, []);41 this.init(middleware);42};4344/**45 * Inherit from `connect.HTTPServer`.46 */4736Server.prototype.__proto__ = connect.HTTPServer.prototype;48app.__proto__ = connect.HTTPServer.prototype;4950/**51 * Initialize the server.52 *53 * @param {Array} middleware54 * @api private55 */5645Server.prototype.init = function(middleware){57app.init = function(middleware){58 var self = this;59 this.cache = {};60 this.match = {};61 this.lookup = {};
75 unmodified lines
137/**138 * When using the vhost() middleware register error handlers.139 */140129Server.prototype.onvhost = function(){141app.onvhost = function(){142 this.registerErrorHandlers();143};144145/**
2 unmodified lines
148 * @return {Server} for chaining149 * @api public150 */151140Server.prototype.registerErrorHandlers = function(){152app.registerErrorHandlers = function(){153 this.errorHandlers.forEach(function(fn){154 this.use(function(err, req, res, next){155 fn.apply(this, arguments);156 });
10 unmodified lines
167 * @return {Server} for chaining168 * @api public169 */170159Server.prototype.use = function(route, middleware){171app.use = function(route, middleware){172 var app, home, handle;173174 if ('string' != typeof route) {175 middleware = route, route = '/';
49 unmodified lines
225 * @return {Server} for chaining226 * @api public227 */228217Server.prototype.mounted = function(fn){229app.mounted = function(fn){230 this.__mounted = fn;231 return this;232};233
3 unmodified lines
237 * @return {Server} for chaining238 * @api public239 */240229Server.prototype.register = function(){241app.register = function(){242 view.register.apply(this, arguments);243 return this;244};245
5 unmodified lines
251 * @return {Server} for chaining252 * @api public253 */254243Server.prototype.helpers =244Server.prototype.locals = function(obj){255app.helpers =256app.locals = function(obj){257 utils.merge(this._locals, obj);258 return this;259};260
5 unmodified lines
266 * @return {Server} for chaining267 * @api public268 */269258Server.prototype.dynamicHelpers = function(obj){270app.dynamicHelpers = function(obj){271 utils.merge(this.dynamicViewHelpers, obj);272 return this;273};274
39 unmodified lines
314 * @return {Server} for chaining315 * @api public316 */317306Server.prototype.param = function(name, fn){318app.param = function(name, fn){319 if (Array.isArray(name)) {320 name.forEach(function(name){321 this.param(name, fn);322 }, this);
12 unmodified lines
335 * @return {Server} for chaining336 * @api public337 */338327Server.prototype.error = function(fn){339app.error = function(fn){340 this.errorHandlers.push(fn);341 return this;342};343
5 unmodified lines
349 * @return {Server} for chaining350 * @api public351 */352341Server.prototype.is = function(type, fn){353app.is = function(type, fn){354 if (!fn) return this.isCallbacks[type];355 this.isCallbacks[type] = fn;356 return this;357};
7 unmodified lines
365 * @return {Server|Mixed} for chaining, or the setting value366 * @api public367 */368357Server.prototype.set = function(setting, val){369app.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 lines
386 * @return {Boolean}387 * @api public388 */389378Server.prototype.enabled = function(setting){390app.enabled = function(setting){391 return !!this.set(setting);392};393394/**
3 unmodified lines
398 * @return {Boolean}399 * @api public400 */401390Server.prototype.disabled = function(setting){402app.disabled = function(setting){403 return !this.set(setting);404};405406/**
3 unmodified lines
410 * @return {Server} for chaining411 * @api public412 */413402Server.prototype.enable = function(setting){414app.enable = function(setting){415 return this.set(setting, true);416};417418/**
3 unmodified lines
422 * @return {Server} for chaining423 * @api public424 */425414Server.prototype.disable = function(setting){426app.disable = function(setting){427 return this.set(setting, false);428};429430/**
4 unmodified lines
435 * @return {Server} for chaining436 * @api public437 */438427Server.prototype.redirect = function(key, url){439app.redirect = function(key, url){440 this.redirects[key] = url;441 return this;442};443
5 unmodified lines
449 * @return {Server} for chaining450 * @api public451 */452441Server.prototype.configure = function(env, fn){453app.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 lines
462463// Generate routing methods464465function generateMethod(method){454 Server.prototype[method] = function(path){466 app[method] = function(path){467 var self = this;468469 // Lookup470 if (1 == arguments.length) {
15 unmodified lines
486methods.forEach(generateMethod);487488// Alias delete as "del"489478Server.prototype.del = Server.prototype.delete;490app.del = app.delete;