Route callback signature changed
Before adoption: this commit came in with the history the project adopted, so no landing records it.
it is now like Express used to be: (req, res, next) instead of: (req, res, params, next) access via req.params
authored by Tj Holowaychuk · committed by Tj Holowaychuk · parents f8ccaa3, 1026f36 · Browse files · 7 files·+30 added−32 removed
This commit
State
Before adoption: this commit came in with the history the project adopted, so no landing records it.
Diff stats
7 files+30 added−32 removed
- tests:+24 added−24 removed
- other:+6 added−8 removed
Provenance
- Commit
75661a2- Tree
0cde170- Author
Tj Holowaychuk <tj@vision-media.ca>- Committer
Tj Holowaychuk <tj@vision-media.ca>- Parent 1
f8ccaa3- Parent 2
1026f36
7 files changed+30 added−32 removed
modified:lib/express/request.js+4 added-4 removed
108 unmodified linesExpand all10911011111211311411311411511611711811711811912012112258 unmodified lines108 unmodified linesExpand all */
http.IncomingMessage.prototype.param = function(name){ // Route params like /user/:id if (this.params.path[name] !== undefined) { return this.params.path[name]; if (this.params[name] !== undefined) { return this.params[name]; } // Query string params if (this.params.get[name] !== undefined) { return this.params.get[name]; if (this.query[name] !== undefined) { return this.query[name]; } // Request body params via connect.bodyDecoder if (this.body && this.body[name] !== undefined) { return this.body[name];58 unmodified linesmodified:lib/express/server.js+2 added-4 removed
39 unmodified lines40 this.set('env', process.env.EXPRESS_ENV || process.connectEnv.name);41 42 // Expose objects to each other43 this.use(function(req, res, next){44- req.params = req.params || {};45- req.params.get = {};44+ req.query = {};45 res.headers = {};46 req.app = res.app = self;47 req.res = res;48 res.req = req;49 req.next = next;50 // Assign req.params.get51 if (req.url.indexOf('?') > 0) {53- // TODO: consider simple substr to increase performance52 var query = url.parse(req.url).query;55- req.params.get = queryString.parse(query);53+ req.query = queryString.parse(query);54 }55 next();56 });57 217 unmodified linesmodified:support/connectnot shown
Its text is not shown, modified.
modified:test/express.test.js+12 added-12 removed
15 unmodified lines16 res.writeHead(200, {});17 res.end('wahoo');18 });19 20- server.put('/user/:id', function(req, res, params){20+ server.put('/user/:id', function(req, res){21 res.writeHead(200, {});22- res.end('updated user ' + params.id)22+ res.end('updated user ' + req.params.id)23 });24 25 assert.response(server,26 { url: '/' },32 unmodified lines59 'test #error()': function(assert){60 // Passing down middleware stack61 var app = express.createServer();62 63- app.get('/', function(req, res, params, next){63+ app.get('/', function(req, res, next){64 next(new Error('broken'));65 });66 67 app.use('/', connect.errorHandler());4 unmodified lines72 73 // Custom handler74 var app = express.createServer();75 76- app.get('/', function(req, res, params, next){76+ app.get('/', function(req, res, next){77 next(new Error('broken'));78 });79 80 app.error(function(err, req, res){6 unmodified lines87 88 // Multiple error()s89 var app = express.createServer();90 91- app.get('/', function(req, res, params, next){91+ app.get('/', function(req, res, next){92 throw new Error('broken');93 });94- app.get('/foo', function(req, res, params, next){94+ app.get('/foo', function(req, res, next){95 throw new Error('oh noes');96 });97 98 app.error(function(err, req, res, next){18 unmodified lines117 118 'test next()': function(assert){119 var app = express.createServer();120 121- app.get('/user.:format?', function(req, res, params, next){122- switch (params.format) {121+ app.get('/user.:format?', function(req, res, next){122+ switch (req.params.format) {123 case 'json':124 res.writeHead(200, {});125 res.end('some json');126 break;18 unmodified lines145 146 'test #use()': function(assert){147 var app = express.createServer();148 149- app.get('/users', function(req, res, params, next){149+ app.get('/users', function(req, res, next){150 next(new Error('fail!!'));151 });152 app.use('/', connect.errorHandler({ showMessage: true }));153 58 unmodified lines212 res.end('last');213 });214 });215 216- app.get('/', function(req, res, params, next){216+ app.get('/', function(req, res, next){217 res.write(' route ');218 next();219 });220 74 unmodified lines295 blog.get('/', function(req, res){296 res.send('blog index');297 });298 299- blog.get('/post/:id', function(req, res, params){300- res.send('blog post ' + params.id);299+ blog.get('/post/:id', function(req, res){300+ res.send('blog post ' + req.params.id);301 });302 303 assert.response(app,304 { url: '/' },12 unmodified linesmodified:test/request.test.js+1 added-1 removed
12 unmodified lines13 module.exports = {14 'test #isXMLHttpRequest': function(assert){15 var app = express.createServer();16 17- app.get('/isxhr', function(req, res, params){17+ app.get('/isxhr', function(req, res){18 assert.equal(req.xhr, req.isXMLHttpRequest);19 res.send(req.isXMLHttpRequest20 ? 'yeaaa boy'21 : 'nope');123 unmodified linesmodified:test/response.test.js+10 added-10 removed
77 unmodified lines78 res.attachment();79 res.send('some stylezzz');80 });81 82- app.get('/*', function(req, res, params){83- res.attachment(params[0]);82+ app.get('/*', function(req, res){83+ res.attachment(req.params[0]);84 res.send('whatever');85 });86 87 assert.response(app,11 unmodified lines99 app2.set('home', '/blog');100 101 app2.redirect('google', 'http://google.com');102 103- app2.redirect('blog', function(req, res, params){104- return params.id105- ? '/user/' + params.id + '/blog'103+ app2.redirect('blog', function(req, res){104+ return req.params.id105+ ? '/user/' + req.params.id + '/blog'106 : null;107 });108 109 app.get('/', function(req, res){63 unmodified lines173 174 'test #sendfile()': function(assert){175 var app = express.createServer();176 177- app.get('/*', function(req, res, params){178- var file = params[0];177+ app.get('/*', function(req, res){178+ var file = req.params[0];179 res.sendfile(__dirname + '/fixtures/' + file);180 });181 182 assert.response(app,12 unmodified lines195 196 'test #download()': function(assert){197 var app = express.createServer();198 199- app.get('/json', function(req, res, params, next){199+ app.get('/json', function(req, res, next){200 res.download(__dirname + '/fixtures/user.json', 'account.json');201 });202 203- app.get('/:file', function(req, res, params, next){204- res.download(__dirname + '/fixtures/' + params.file);203+ app.get('/:file', function(req, res, next){204+ res.download(__dirname + '/fixtures/' + req.params.file);205 });206 207 assert.response(app,208 { url: '/user.json' },13 unmodified linesmodified:test/view.test.js+1 added-1 removed
182 unmodified lines183 }184 });185 186 var ret = app.dynamicHelpers({187- session: function(req, res, params){187+ session: function(req, res){188 assert.equal('object', typeof req, 'Test dynamic helper req');189 assert.equal('object', typeof req, 'Test dynamic helper res');190 assert.equal('object', typeof req, 'Test dynamic helper params');191 assert.ok(this instanceof express.Server, 'Test dynamic helper app scope');153 unmodified lines