Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Route callback signature changed

it is now like Express used to be: (req, res, next)
instead of: (req, res, params, next)

access via req.params
  • Loading branch information...
commit 75661a2266bbf25480be56960513cf9405ba3ba9 2 parents f8ccaa3 + 1026f36
@tj tj authored
View
8 lib/express/request.js
@@ -110,12 +110,12 @@ http.IncomingMessage.prototype.accepts = function(type){
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) {
View
6 lib/express/server.js
@@ -41,8 +41,7 @@ var Server = exports = module.exports = function Server(middleware){
// Expose objects to each other
this.use(function(req, res, next){
- req.params = req.params || {};
- req.params.get = {};
+ req.query = {};
res.headers = {};
req.app = res.app = self;
req.res = res;
@@ -50,9 +49,8 @@ var Server = exports = module.exports = function Server(middleware){
req.next = next;
// Assign req.params.get
if (req.url.indexOf('?') > 0) {
- // TODO: consider simple substr to increase performance
var query = url.parse(req.url).query;
- req.params.get = queryString.parse(query);
+ req.query = queryString.parse(query);
}
next();
});
2  support/connect
@@ -1 +1 @@
-Subproject commit f455ec7e78d488269ea4ce107ddba9e7bd20b52a
+Subproject commit fadf5db5d3ae782ec0ee7c0bee2876433cceb68e
View
24 test/express.test.js
@@ -17,9 +17,9 @@ module.exports = {
res.end('wahoo');
});
- server.put('/user/:id', function(req, res, params){
+ server.put('/user/:id', function(req, res){
res.writeHead(200, {});
- res.end('updated user ' + params.id)
+ res.end('updated user ' + req.params.id)
});
assert.response(server,
@@ -60,7 +60,7 @@ module.exports = {
// Passing down middleware stack
var app = express.createServer();
- app.get('/', function(req, res, params, next){
+ app.get('/', function(req, res, next){
next(new Error('broken'));
});
@@ -73,7 +73,7 @@ module.exports = {
// Custom handler
var app = express.createServer();
- app.get('/', function(req, res, params, next){
+ app.get('/', function(req, res, next){
next(new Error('broken'));
});
@@ -88,10 +88,10 @@ module.exports = {
// Multiple error()s
var app = express.createServer();
- app.get('/', function(req, res, params, next){
+ app.get('/', function(req, res, next){
throw new Error('broken');
});
- app.get('/foo', function(req, res, params, next){
+ app.get('/foo', function(req, res, next){
throw new Error('oh noes');
});
@@ -118,8 +118,8 @@ module.exports = {
'test next()': function(assert){
var app = express.createServer();
- app.get('/user.:format?', function(req, res, params, next){
- switch (params.format) {
+ app.get('/user.:format?', function(req, res, next){
+ switch (req.params.format) {
case 'json':
res.writeHead(200, {});
res.end('some json');
@@ -146,7 +146,7 @@ module.exports = {
'test #use()': function(assert){
var app = express.createServer();
- app.get('/users', function(req, res, params, next){
+ app.get('/users', function(req, res, next){
next(new Error('fail!!'));
});
app.use('/', connect.errorHandler({ showMessage: true }));
@@ -213,7 +213,7 @@ module.exports = {
});
});
- app.get('/', function(req, res, params, next){
+ app.get('/', function(req, res, next){
res.write(' route ');
next();
});
@@ -296,8 +296,8 @@ module.exports = {
res.send('blog index');
});
- blog.get('/post/:id', function(req, res, params){
- res.send('blog post ' + params.id);
+ blog.get('/post/:id', function(req, res){
+ res.send('blog post ' + req.params.id);
});
assert.response(app,
View
2  test/request.test.js
@@ -14,7 +14,7 @@ module.exports = {
'test #isXMLHttpRequest': function(assert){
var app = express.createServer();
- app.get('/isxhr', function(req, res, params){
+ app.get('/isxhr', function(req, res){
assert.equal(req.xhr, req.isXMLHttpRequest);
res.send(req.isXMLHttpRequest
? 'yeaaa boy'
View
20 test/response.test.js
@@ -79,8 +79,8 @@ module.exports = {
res.send('some stylezzz');
});
- app.get('/*', function(req, res, params){
- res.attachment(params[0]);
+ app.get('/*', function(req, res){
+ res.attachment(req.params[0]);
res.send('whatever');
});
@@ -100,9 +100,9 @@ module.exports = {
app2.redirect('google', 'http://google.com');
- app2.redirect('blog', function(req, res, params){
- return params.id
- ? '/user/' + params.id + '/blog'
+ app2.redirect('blog', function(req, res){
+ return req.params.id
+ ? '/user/' + req.params.id + '/blog'
: null;
});
@@ -174,8 +174,8 @@ module.exports = {
'test #sendfile()': function(assert){
var app = express.createServer();
- app.get('/*', function(req, res, params){
- var file = params[0];
+ app.get('/*', function(req, res){
+ var file = req.params[0];
res.sendfile(__dirname + '/fixtures/' + file);
});
@@ -196,12 +196,12 @@ module.exports = {
'test #download()': function(assert){
var app = express.createServer();
- app.get('/json', function(req, res, params, next){
+ app.get('/json', function(req, res, next){
res.download(__dirname + '/fixtures/user.json', 'account.json');
});
- app.get('/:file', function(req, res, params, next){
- res.download(__dirname + '/fixtures/' + params.file);
+ app.get('/:file', function(req, res, next){
+ res.download(__dirname + '/fixtures/' + req.params.file);
});
assert.response(app,
View
2  test/view.test.js
@@ -184,7 +184,7 @@ module.exports = {
});
var ret = app.dynamicHelpers({
- session: function(req, res, params){
+ session: function(req, res){
assert.equal('object', typeof req, 'Test dynamic helper req');
assert.equal('object', typeof req, 'Test dynamic helper res');
assert.equal('object', typeof req, 'Test dynamic helper params');
Please sign in to comment.
Something went wrong with that request. Please try again.