2 spaces in server.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 347aa56 · Browse files · 1 file·+126 added−126 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+126 added−126 removed
- other:+126 added−126 removed
Provenance
- Commit
877cfe9- Tree
5383364- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent
347aa56
1 file changed+126 added−126 removed
modified:lib/express/server.js+126 added-126 removed
7 unmodified lines8 /**9 * Module dependencies.10 */11 12-var url = require('url'),13- view = require('./view'),14- connect = require('connect'),15- utils = require('connect/utils'),16- queryString = require('querystring'),17- router = require('connect/middleware/router');12+var url = require('url')13+ , view = require('./view')14+ , connect = require('connect')15+ , utils = connect.utils16+ , queryString = require('querystring')17+ , router = require('connect/middleware/router');18 19 /**20 * Initialize a new `Server` with optional `middleware`.21 *1 unmodified line23 * @api public24 */25 26 var Server = exports = module.exports = function Server(middleware){27- var self = this;28- this.config = {};29- this.settings = {};30- this.redirects = {};31- this.viewHelpers = {};32- this.dynamicViewHelpers = {};33- this.errorHandlers = [];34- connect.Server.call(this, middleware || []);27+ var self = this;28+ this.config = {};29+ this.settings = {};30+ this.redirects = {};31+ this.viewHelpers = {};32+ this.dynamicViewHelpers = {};33+ this.errorHandlers = [];34+ connect.Server.call(this, middleware || []);35 36- // Default "home" to / 37- this.set('home', '/');36+ // Default "home" to / 37+ this.set('home', '/');38 39- // DEPRECATED: remove in 1.040- if (process.env.EXPRESS_ENV) {41- process.env.NODE_ENV = process.env.EXPRESS_ENV;42- console.warn('\x1b[33mWarning\x1b[0m: EXPRESS_ENV is deprecated, use NODE_ENV.');43- }39+ // DEPRECATED: remove in 1.040+ if (process.env.EXPRESS_ENV) {41+ process.env.NODE_ENV = process.env.EXPRESS_ENV;42+ console.warn('\x1b[33mWarning\x1b[0m: EXPRESS_ENV is deprecated, use NODE_ENV.');43+ }44 45- // Set "env" to NODE_ENV, defaulting to "development"46- this.set('env', process.env.NODE_ENV || 'development');45+ // Set "env" to NODE_ENV, defaulting to "development"46+ this.set('env', process.env.NODE_ENV || 'development');47 48- // Expose objects to each other49- this.use(function(req, res, next){50- req.query = {};51- res.headers = {};52- req.app = res.app = self;53- req.res = res;54- res.req = req;55- req.next = next;56- // Assign req.params.get57- if (req.url.indexOf('?') > 0) {58- var query = url.parse(req.url).query;59- req.query = exports.parseQueryString(query);60- }61- next();62- });48+ // Expose objects to each other49+ this.use(function(req, res, next){50+ req.query = {};51+ res.headers = {};52+ req.app = res.app = self;53+ req.res = res;54+ res.req = req;55+ req.next = next;56+ // Assign req.params.get57+ if (req.url.indexOf('?') > 0) {58+ var query = url.parse(req.url).query;59+ req.query = exports.parseQueryString(query);60+ }61+ next();62+ });63 64- // Use router, expose as app.get(), etc65- var fn = router(function(app){ self.routes = app; });66- this.__defineGetter__('router', function(){67- this.__usedRouter = true;68- return fn;69- });64+ // Use router, expose as app.get(), etc65+ var fn = router(function(app){ self.routes = app; });66+ this.__defineGetter__('router', function(){67+ this.__usedRouter = true;68+ return fn;69+ });70 };71 72 /**73 * Inherit from `connect.Server`.11 unmodified lines85 * Proxy in order to register error handlers.86 */87 88 Server.prototype.listen = function(){89- this.registerErrorHandlers();90- connect.Server.prototype.listen.apply(this, arguments);89+ this.registerErrorHandlers();90+ connect.Server.prototype.listen.apply(this, arguments);91 };92 93 /**94 * Proxy in order to register error handlers.95 */96 97 Server.prototype.listenFD = function(){98- this.registerErrorHandlers();99- connect.Server.prototype.listenFD.apply(this, arguments);98+ this.registerErrorHandlers();99+ connect.Server.prototype.listenFD.apply(this, arguments);100 };101 102 /**103 * Register error handlers. This is automatically3 unmodified lines107 * @api public108 */109 110 Server.prototype.registerErrorHandlers = function(){111- this.errorHandlers.forEach(function(fn){112- this.use(function(err, req, res, next){113- fn.apply(this, arguments);114- });115- }, this);116- return this;111+ this.errorHandlers.forEach(function(fn){112+ this.use(function(err, req, res, next){113+ fn.apply(this, arguments);114+ });115+ }, this);116+ return this;117 };118 119 /**120 * Proxy `connect.Server#use()` to apply settings to5 unmodified lines126 * @api public127 */128 129 Server.prototype.use = function(route, middleware){130- if (typeof route !== 'string') {131- middleware = route, route = '/';132- }130+ if (typeof route !== 'string') {131+ middleware = route, route = '/';132+ }133 134- connect.Server.prototype.use.call(this, route, middleware);134+ connect.Server.prototype.use.call(this, route, middleware);135 136- // Mounted an app137- if (middleware instanceof Server) {138- // Home is /:route/:home139- var app = middleware,140- home = app.set('home');141- if (home === '/') home = '';142- app.set('home', (app.route || '') + home);143- app.parent = this;144- // Mounted hook145- if (app.__mounted) app.__mounted.call(app, this);146- }136+ // Mounted an app137+ if (middleware instanceof Server) {138+ // Home is /:route/:home139+ var app = middleware140+ , home = app.set('home');141+ if (home === '/') home = '';142+ app.set('home', (app.route || '') + home);143+ app.parent = this;144+ // Mounted hook145+ if (app.__mounted) app.__mounted.call(app, this);146+ }147 148- return this;148+ return this;149 };150 151 /**152 * Assign a callback `fn` which is called16 unmodified lines169 * @api public170 */171 172 Server.prototype.mounted = function(fn){173- this.__mounted = fn;174- return this;173+ this.__mounted = fn;174+ return this;175 };176 177 /**178 * See: view.register.2 unmodified lines181 * @api public182 */183 184 Server.prototype.register = function(){185- view.register.apply(this, arguments);186- return this;185+ view.register.apply(this, arguments);186+ return this;187 };188 189 /**190 * Register the given view helpers `obj`. This method4 unmodified lines195 * @api public196 */197 198 Server.prototype.helpers = function(obj){199- utils.merge(this.viewHelpers, obj);200- return this;199+ utils.merge(this.viewHelpers, obj);200+ return this;201 };202 203 /**204 * Register the given dynamic view helpers `obj`. This method4 unmodified lines209 * @api public210 */211 212 Server.prototype.dynamicHelpers = function(obj){213- utils.merge(this.dynamicViewHelpers, obj);214- return this;213+ utils.merge(this.dynamicViewHelpers, obj);214+ return this;215 };216 217 /**218 * Assign a custom exception handler callback `fn`.4 unmodified lines223 * @api public224 */225 226 Server.prototype.error = function(fn){227- this.errorHandlers.push(fn);228- return this;227+ this.errorHandlers.push(fn);228+ return this;229 };230 231 /**232 * Assign `setting` to `val`, or return `setting`'s value.5 unmodified lines238 * @api public239 */240 241 Server.prototype.set = function(setting, val){242- if (val === undefined) {243- if (this.settings.hasOwnProperty(setting)) {244- return this.settings[setting];245- } else if (this.parent) {246- return this.parent.set(setting);247- }248- } else {249- this.settings[setting] = val;250- return this;242+ if (val === undefined) {243+ if (this.settings.hasOwnProperty(setting)) {244+ return this.settings[setting];245+ } else if (this.parent) {246+ return this.parent.set(setting);247 }248+ } else {249+ this.settings[setting] = val;250+ return this;251+ }252 };253 254 /**255 * Enable `setting`.3 unmodified lines259 * @api public260 */261 262 Server.prototype.enable = function(setting){263- return this.set(setting, true);263+ return this.set(setting, true);264 };265 266 /**267 * Disable `setting`.3 unmodified lines271 * @api public272 */273 274 Server.prototype.disable = function(setting){275- return this.set(setting, false);275+ return this.set(setting, false);276 };277 278 /**279 * Redirect `key` to `url`.4 unmodified lines284 * @api public285 */286 287 Server.prototype.redirect = function(key, url){288- this.redirects[key] = url;289- return this;288+ this.redirects[key] = url;289+ return this;290 };291 292 /**293 * Configure callback for the given `env`.4 unmodified lines298 * @api public299 */300 301 Server.prototype.configure = function(env, fn){302- if (typeof env === 'function') {303- fn = env, env = 'all';304- }305- if (env === 'all' || this.set('env') === env) {306- fn.call(this);307- }308- return this;302+ if (typeof env === 'function') {303+ fn = env, env = 'all';304+ }305+ if (env === 'all' || this.set('env') === env) {306+ fn.call(this);307+ }308+ return this;309 };310 311 // Generate routing methods312 313 (function(method){314- Server.prototype[method] = function(path, fn){315- var self = this;314+ Server.prototype[method] = function(path, fn){315+ var self = this;316 317- // Ensure router is mounted318- if (!this.__usedRouter) {319- this.use(this.router);320- }317+ // Ensure router is mounted318+ if (!this.__usedRouter) {319+ this.use(this.router);320+ }321 322- // Route specific middleware support323- if (arguments.length > 2) {324- var args = Array.prototype.slice.call(arguments, 1);325- fn = args.pop();326- (function stack(middleware){327- middleware.forEach(function(fn){328- if (Array.isArray(fn)) {329- stack(fn);330- } else {331- self[method](path, fn);332- }333- });334- })(args);335- }322+ // Route specific middleware support323+ if (arguments.length > 2) {324+ var args = Array.prototype.slice.call(arguments, 1);325+ fn = args.pop();326+ (function stack(middleware){327+ middleware.forEach(function(fn){328+ if (Array.isArray(fn)) {329+ stack(fn);330+ } else {331+ self[method](path, fn);332+ }333+ });334+ })(args);335+ }336 337- // Generate the route338- this.routes[method](path, fn);339- return this;340- };341- return arguments.callee;337+ // Generate the route338+ this.routes[method](path, fn);339+ return this;340+ };341+ return arguments.callee;342 })('get')('post')('put')('delete');343 344 // Alias delete as "del"345 346-Server.prototype.del = Server.prototype.delete;346+Server.prototype.del = Server.prototype.delete;