Skip to content
Myr

Added support for multiple env app.configure() calls. Closes #735

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 6b47271 · Browse files · 2 files+39 added−6 removed
This commit

State

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

Diff stats

2 files+39 added−6 removed

  • tests:+17 added−2 removed
  • other:+22 added−4 removed

2 files+39 added−6 removed

modified:lib/http.js+22 added-4 removed
469 unmodified lines
470 return this;471};472473/**474 * Configure callback for the given `env`.474 * Configure callback for zero or more`env`.475 *476 * Examples:477 *478 * app.configure(function(){479 * // executed for all envs480 * });481 *482 *483 * app.configure('stage', function(){484 * // executed staging env485 * });486 *487 * app.configure('stage', 'production', function(){488 * // executed for stage and production489 * });490 *476 * @param {String} env491 * @param {String} env...492 * @param {Function} fn493 * @return {Server} for chaining494 * @api public495 */496497app.configure = function(env, fn){483 if ('function' == typeof env) fn = env, env = 'all';484 if ('all' == env || env == this.settings.env) fn.call(this);498 var envs = 'all'499 , args = toArray(arguments);500 fn = args.pop();501 if (args.length) envs = args;502 if ('all' == envs || ~envs.indexOf(this.settings.env)) fn.call(this);503 return this;504};505506/**
36 unmodified lines
modified:test/express.test.js+17 added-2 removed
234 unmodified lines
235 var calls = [];236 var server = express.createServer();237 server.set('env', 'development');238 239 // Config blocks239 var ret = server.configure(function(){240 assert.equal(this, server, 'Test context of configure() is the server');241 calls.push('any');242 }).configure('development', function(){
52 unmodified lines
295 assert.response(app,296 { url: '/' },297 { body: 'first route last' });298 },300 299300 'test #configure() multiple envs': function(){301 var app = express.createServer();302 app.set('env', 'prod');303 var calls = [];304305 app.configure('stage', 'prod', function(){306 calls.push('stage/prod');307 });308309 app.configure('prod', function(){310 calls.push('prod');311 });312313 calls.should.eql(['stage/prod', 'prod']);314 },315316 'test #set()': function(){317 var app = express.createServer();318 var ret = app.set('title', 'My App').set('something', 'else');319 ret.should.equal(app);
173 unmodified lines