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
Provenance
- Commit
ac2cbef- Tree
2edbf4a- Author
Roman Shtylman <shtylman@gmail.com>- Committer
Roman Shtylman <shtylman@gmail.com>- Parent 1
185b526- Parent 2
dff22e9
5 files changed+8 added−174 removed
modified:lib/application.js+2 added-60 removed
80 unmodified lines81 this.set('view', View);82 this.set('views', process.cwd() + '/views');83 this.set('jsonp callback name', 'callback');84 85- this.configure('development', function(){86- this.set('json spaces', 2);87- });88-89- this.configure('production', function(){85+ if (this.get('env') === 'production') {86 this.enable('view cache');91- });87+ };88 };89 90 /**91 * Proxy `connect#use()` to apply settings to242 unmodified lines334 return this.set(setting, false);335 };336 337 /**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- */385-386-app.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-};394-395-/**338 * Delegate `.VERB(...)` calls to `router.VERB(...)`.339 */340 341 methods.forEach(function(method){135 unmodified linesdeleted:test/config.env.js-96 removed
1-2-var express = require('../');3-4-describe('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 = [];10-11- app.configure(function(){12- calls.push('all');13- });14-15- app.configure('test', function(){16- calls.push('test');17- });18-19- app.configure('test', function(){20- calls.push('test 2');21- });22-23- calls.should.eql(['all', 'test', 'test 2'])24- })25- })26-27- describe('when an env is given', function(){28- it('should only execute the matching env', function(){29- var app = express();30- var calls = [];31-32- app.set('env', 'development');33-34- app.configure('development', function(){35- calls.push('dev');36- });37-38- app.configure('test', function(){39- calls.push('test');40- });41-42- 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 = [];50-51- app.set('env', 'development');52-53- app.configure('development', function(){54- calls.push('dev');55- });56-57- 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- });68-69- calls.should.eql(['dev', 'dev 2', 'dev 3']);70- })71- })72-73- it('should execute in order as defined', function(){74- var app = express();75- var calls = [];76-77- app.configure(function(){78- calls.push('all');79- });80- 81- app.configure('test', function(){82- calls.push('test');83- });84-85- app.configure(function(){86- calls.push('all 2');87- });88-89- app.configure('test', function(){90- calls.push('test 2');91- });92-93- calls.should.eql(['all', 'test', 'all 2', 'test 2'])94- })95- })96-})modified:test/res.json.js+3 added-10 removed
50 unmodified lines5152535455555657585934 unmodified lines949596979899989910110210310410510610010110210313 unmodified lines11711811912012812112212312412552 unmodified lines50 unmodified lines done(); }) }) })
describe('when given an object', function(){ it('should respond with json', function(done){ var app = express();
34 unmodified lines }) })
describe('"json spaces" setting', function(){ it('should default to 2 in development', function(){ process.env.NODE_ENV = 'development'; it('should be undefined by default', function(){ var app = express(); app.get('json spaces').should.equal(2); process.env.NODE_ENV = 'test'; })
it('should be undefined otherwise', function(){ var app = express(); assert(undefined === app.get('json spaces')); })
it('should be passed to JSON.stringify()', function(done){13 unmodified lines }); }) }) })
describe('.json(status, object)', function(){ it('should respond with json and set the .statusCode', function(done){ var app = express();
52 unmodified linesmodified:test/res.jsonp.js+1 added-8 removed
179 unmodified lines180 })181 })182 183 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- })190-191- it('should be undefined otherwise', function(){192- var app = express();186 assert(undefined === app.get('json spaces'));187 })188 189 it('should be passed to JSON.stringify()', function(done){56 unmodified linesmodified:History.md+2 added
2 unmodified lines3 4 * 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