Skip to content
Myr

Merge pull request #1899 from visionmedia/remove-configure

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Remove app.configure

authored by Roman Shtylman · committed by Roman Shtylman · parents 185b526, dff22e9 · Browse files · 5 files+8 added−174 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

5 files+8 added−174 removed

  • tests:+4 added−114 removed
  • other:+4 added−60 removed

5 files+8 added−174 removed

modified:lib/application.js+2 added-60 removed
80 unmodified lines
81 this.set('view', View);82 this.set('views', process.cwd() + '/views');83 this.set('jsonp callback name', 'callback');8485 this.configure('development', function(){86 this.set('json spaces', 2);87 });8889 this.configure('production', function(){85 if (this.get('env') === 'production') {86 this.enable('view cache');91 });87 };88};8990/**91 * Proxy `connect#use()` to apply settings to
242 unmodified lines
334 return this.set(setting, false);335};336337/**342 * Configure callback for zero or more envs,343 * when no `env` is specified that callback will344 * be invoked for all environments. Any combination345 * can be used multiple times, in any order desired.346 *347 * Examples:348 *349 * app.configure(function(){350 * // executed for all envs351 * });352 *353 * app.configure('stage', function(){354 * // executed staging env355 * });356 *357 * app.configure('stage', 'production', function(){358 * // executed for stage and production359 * });360 *361 * Note:362 *363 * These callbacks are invoked immediately, and364 * are effectively sugar for the following:365 *366 * var env = process.env.NODE_ENV || 'development';367 *368 * switch (env) {369 * case 'development':370 * ...371 * break;372 * case 'stage':373 * ...374 * break;375 * case 'production':376 * ...377 * break;378 * }379 *380 * @param {String} env...381 * @param {Function} fn382 * @return {app} for chaining383 * @api public384 */385386app.configure = function(env, fn){387 var envs = 'all'388 , args = [].slice.call(arguments);389 fn = args.pop();390 if (args.length) envs = args;391 if ('all' == envs || ~envs.indexOf(this.settings.env)) fn.call(this);392 return this;393};394395/**338 * Delegate `.VERB(...)` calls to `router.VERB(...)`.339 */340341methods.forEach(function(method){
135 unmodified lines
deleted:test/config.env.js-96 removed
12var express = require('../');34describe('config', function(){5 describe('.configure()', function(){6 describe('when no env is given', function(){7 it('should always execute', function(){8 var app = express();9 var calls = [];1011 app.configure(function(){12 calls.push('all');13 });1415 app.configure('test', function(){16 calls.push('test');17 });1819 app.configure('test', function(){20 calls.push('test 2');21 });2223 calls.should.eql(['all', 'test', 'test 2'])24 })25 })2627 describe('when an env is given', function(){28 it('should only execute the matching env', function(){29 var app = express();30 var calls = [];3132 app.set('env', 'development');3334 app.configure('development', function(){35 calls.push('dev');36 });3738 app.configure('test', function(){39 calls.push('test');40 });4142 calls.should.eql(['dev']);43 })44 })45 46 describe('when several envs are given', function(){47 it('should execute when matching one', function(){48 var app = express();49 var calls = [];5051 app.set('env', 'development');5253 app.configure('development', function(){54 calls.push('dev');55 });5657 app.configure('test', 'development', function(){58 calls.push('dev 2');59 });60 61 app.configure('development', 'test', function(){62 calls.push('dev 3');63 });64 65 app.configure('test', function(){66 calls.push('dev 3');67 });6869 calls.should.eql(['dev', 'dev 2', 'dev 3']);70 })71 })7273 it('should execute in order as defined', function(){74 var app = express();75 var calls = [];7677 app.configure(function(){78 calls.push('all');79 });80 81 app.configure('test', function(){82 calls.push('test');83 });8485 app.configure(function(){86 calls.push('all 2');87 });8889 app.configure('test', function(){90 calls.push('test 2');91 });9293 calls.should.eql(['all', 'test', 'all 2', 'test 2'])94 })95 })96})
modified:test/res.json.js+3 added-10 removed
modified:test/res.jsonp.js+1 added-8 removed
179 unmodified lines
180 })181 })182183 describe('"json spaces" setting', function(){184 it('should default to 2 in development', function(){185 process.env.NODE_ENV = 'development';184 it('should be undefined by default', function(){185 var app = express();187 app.get('json spaces').should.equal(2);188 process.env.NODE_ENV = 'test';189 })190191 it('should be undefined otherwise', function(){192 var app = express();186 assert(undefined === app.get('json spaces'));187 })188189 it('should be passed to JSON.stringify()', function(done){
56 unmodified lines
modified:History.md+2 added
2 unmodified lines
34 * remove:5 - express(1) - moved to [express-generator](https://github.com/expressjs/generator)6 - `req.accepted*` - use `req.accepts*()` instead7 - `app.configure` - use logic in your own app code8 * change:9 - `req.accepts*` -> `req.accepts*s` - i.e. `req.acceptsEncoding` -> `req.acceptsEncodings`10 - `req.params` is now an object instead of an array11 - `json spaces` no longer enabled by default in development12 * refactor:13 - `req.accepts*` with [accepts](https://github.com/expressjs/accepts)14 - `req.is` with [type-is](https://github.com/expressjs/type-is)15
1252 unmodified lines