mirror of
https://github.com/expressjs/express.git
synced 2026-02-27 03:07:33 +00:00
Compare commits
9 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1bb798d963 | ||
|
|
91997e9c53 | ||
|
|
1393187040 | ||
|
|
6e69c880d9 | ||
|
|
59dcd03972 | ||
|
|
11482546a2 | ||
|
|
1ce43dd347 | ||
|
|
d1bfe137d4 | ||
|
|
9d7452cdc2 |
@@ -1,4 +1,11 @@
|
||||
|
||||
2.3.10 / 2011-05-27
|
||||
==================
|
||||
|
||||
* Added `req.route`, exposing the current route
|
||||
* Added _package.json_ generation support to `express(1)`
|
||||
* Fixed call to `app.param()` function for optional params. Closes #682
|
||||
|
||||
2.3.9 / 2011-05-25
|
||||
==================
|
||||
|
||||
|
||||
29
bin/express
29
bin/express
@@ -11,7 +11,7 @@ var fs = require('fs')
|
||||
* Framework version.
|
||||
*/
|
||||
|
||||
var version = '2.3.9';
|
||||
var version = '2.3.10';
|
||||
|
||||
/**
|
||||
* Add session support.
|
||||
@@ -343,19 +343,22 @@ function createApplicationAt(path) {
|
||||
// Template support
|
||||
app = app.replace(':TEMPLATE', templateEngine);
|
||||
|
||||
write(path + '/app.js', app);
|
||||
// package.json
|
||||
var json = '{\n';
|
||||
json += ' "name": "application-name"\n';
|
||||
json += ' , "version": "0.0.1"\n';
|
||||
json += ' , "private": true\n';
|
||||
if (cssEngine || templateEngine) {
|
||||
var comma = cssEngine ? ' ,' : '';
|
||||
json += ' , "dependencies": {\n';
|
||||
if (cssEngine) json += ' "' + cssEngine + '": ">= 0.0.1"\n';
|
||||
if (templateEngine) json += ' ' + comma + ' "' + templateEngine + '": ">= 0.0.1"\n';
|
||||
json += ' }\n';
|
||||
}
|
||||
json += '}';
|
||||
|
||||
// Suggestions
|
||||
process.on('exit', function(){
|
||||
if (cssEngine) {
|
||||
console.log(' - make sure you have installed %s: \x1b[33m$ npm install %s\x1b[0m'
|
||||
, cssEngine
|
||||
, cssEngine);
|
||||
}
|
||||
console.log(' - make sure you have installed %s: \x1b[33m$ npm install %s\x1b[0m'
|
||||
, templateEngine
|
||||
, templateEngine);
|
||||
});
|
||||
write(path + '/package.json', json);
|
||||
write(path + '/app.js', app);
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ var exports = module.exports = connect.middleware;
|
||||
* Framework version.
|
||||
*/
|
||||
|
||||
exports.version = '2.3.9';
|
||||
exports.version = '2.3.10';
|
||||
|
||||
/**
|
||||
* Shortcut for `new Server(...)`.
|
||||
|
||||
@@ -193,7 +193,7 @@ Router.prototype._dispatch = function(req, res, next){
|
||||
}
|
||||
|
||||
// match route
|
||||
route = self._match(req, i);
|
||||
req.route = route = self._match(req, i);
|
||||
|
||||
// implied OPTIONS
|
||||
if (!route && 'OPTIONS' == req.method) return self._options(req, res);
|
||||
@@ -209,8 +209,8 @@ Router.prototype._dispatch = function(req, res, next){
|
||||
|
||||
(function param(err) {
|
||||
var key = keys[i++]
|
||||
, val = req.params[key]
|
||||
, fn = params[key]
|
||||
, val = key && req.params[key.name]
|
||||
, fn = key && params[key.name]
|
||||
, ret;
|
||||
|
||||
try {
|
||||
@@ -218,7 +218,7 @@ Router.prototype._dispatch = function(req, res, next){
|
||||
nextRoute();
|
||||
} else if (err) {
|
||||
next(err);
|
||||
} else if (fn) {
|
||||
} else if (fn && undefined !== val) {
|
||||
fn(req, res, param, val);
|
||||
} else if (key) {
|
||||
param();
|
||||
@@ -329,7 +329,7 @@ Router.prototype._match = function(req, i){
|
||||
? decodeURIComponent(captures[j])
|
||||
: captures[j];
|
||||
if (key) {
|
||||
route.params[key] = val;
|
||||
route.params[key.name] = val;
|
||||
} else {
|
||||
route.params.push(val);
|
||||
}
|
||||
|
||||
@@ -70,7 +70,7 @@ function normalize(path, keys, sensitive) {
|
||||
.concat('/?')
|
||||
.replace(/\/\(/g, '(?:/')
|
||||
.replace(/(\/)?(\.)?:(\w+)(?:(\(.*?\)))?(\?)?/g, function(_, slash, format, key, capture, optional){
|
||||
keys.push(key);
|
||||
keys.push({ name: key, optional: !! optional });
|
||||
slash = slash || '';
|
||||
return ''
|
||||
+ (optional ? '' : slash)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
{
|
||||
"name": "express",
|
||||
"description": "Sinatra inspired web development framework",
|
||||
"version": "2.3.9",
|
||||
"version": "2.3.10",
|
||||
"author": "TJ Holowaychuk <tj@vision-media.ca>",
|
||||
"contributors": [
|
||||
{ "name": "TJ Holowaychuk", "email": "tj@vision-media.ca" },
|
||||
|
||||
@@ -461,5 +461,17 @@ module.exports = {
|
||||
assert.response(app,
|
||||
{ url: '/another' },
|
||||
{ body: 'got /another' });
|
||||
},
|
||||
|
||||
'invalid chars': function(){
|
||||
var app = express.createServer();
|
||||
|
||||
app.get('/:name', function(req, res, next){
|
||||
res.send('invalid');
|
||||
});
|
||||
|
||||
assert.response(app,
|
||||
{ url: '/%a0' },
|
||||
{ status: 500 });
|
||||
}
|
||||
};
|
||||
|
||||
@@ -74,6 +74,38 @@ module.exports = {
|
||||
});
|
||||
},
|
||||
|
||||
'test precedence': function(){
|
||||
var app = express.createServer();
|
||||
|
||||
var hits = [];
|
||||
|
||||
app.all('*', function(req, res, next){
|
||||
hits.push('all');
|
||||
next();
|
||||
});
|
||||
|
||||
app.get('/foo', function(req, res, next){
|
||||
hits.push('GET /foo');
|
||||
next();
|
||||
});
|
||||
|
||||
app.get('/foo', function(req, res, next){
|
||||
hits.push('GET /foo2');
|
||||
next();
|
||||
});
|
||||
|
||||
app.put('/foo', function(req, res, next){
|
||||
hits.push('PUT /foo');
|
||||
next();
|
||||
});
|
||||
|
||||
assert.response(app,
|
||||
{ url: '/foo' },
|
||||
function(){
|
||||
hits.should.eql(['all', 'GET /foo', 'GET /foo2']);
|
||||
});
|
||||
},
|
||||
|
||||
'test named capture groups': function(){
|
||||
var app = express.createServer();
|
||||
|
||||
@@ -106,7 +138,7 @@ module.exports = {
|
||||
{ body: 'Cannot GET /user/ab' });
|
||||
},
|
||||
|
||||
'test .param()': function(){
|
||||
'test app.param()': function(){
|
||||
var app = express.createServer();
|
||||
|
||||
var users = [
|
||||
@@ -137,6 +169,35 @@ module.exports = {
|
||||
{ url: '/user/1' },
|
||||
{ body: 'user tobi' });
|
||||
},
|
||||
|
||||
'test app.param() optional execution': function(beforeExit){
|
||||
var app = express.createServer()
|
||||
, calls = 0;
|
||||
|
||||
var months = ['Jan', 'Feb', 'Mar'];
|
||||
|
||||
app.param('month', function(req, res, next, n){
|
||||
req.params.month = months[n];
|
||||
++calls;
|
||||
next();
|
||||
});
|
||||
|
||||
app.get('/calendar/:month?', function(req, res, next){
|
||||
res.send(req.params.month || months[0]);
|
||||
});
|
||||
|
||||
assert.response(app,
|
||||
{ url: '/calendar' },
|
||||
{ body: 'Jan' });
|
||||
|
||||
assert.response(app,
|
||||
{ url: '/calendar/1' },
|
||||
{ body: 'Feb' });
|
||||
|
||||
beforeExit(function(){
|
||||
calls.should.equal(1);
|
||||
});
|
||||
},
|
||||
|
||||
'test OPTIONS': function(){
|
||||
var app = express.createServer();
|
||||
@@ -168,7 +229,7 @@ module.exports = {
|
||||
route.path.should.equal('/user/:id');
|
||||
route.regexp.should.be.an.instanceof(RegExp);
|
||||
route.method.should.equal('get');
|
||||
route.keys.should.eql(['id']);
|
||||
route.keys.should.eql([{ name: 'id', optional: false }]);
|
||||
|
||||
app.get('/user').should.have.length(1);
|
||||
app.get('/user/:id').should.have.length(1);
|
||||
@@ -230,7 +291,7 @@ module.exports = {
|
||||
route.path.should.equal('/user/:id');
|
||||
route.regexp.should.be.an.instanceof(RegExp);
|
||||
route.method.should.equal('get');
|
||||
route.keys.should.eql(['id']);
|
||||
route.keys.should.eql([{ name: 'id', optional: false }]);
|
||||
//route.params.id.should.equal('12');
|
||||
|
||||
app.match.get('/user').should.have.length(1);
|
||||
@@ -298,5 +359,27 @@ module.exports = {
|
||||
assert.response(app,
|
||||
{ url: '/foo', method: 'OPTIONS' },
|
||||
{ body: 'whatever', headers: { Allow: 'GET' }});
|
||||
},
|
||||
|
||||
'test req.route': function(){
|
||||
var app = express.createServer();
|
||||
|
||||
var routes = [];
|
||||
|
||||
app.get('/:foo?', function(req, res, next){
|
||||
routes.push(req.route.path);
|
||||
next();
|
||||
});
|
||||
|
||||
app.get('/foo', function(req, res, next){
|
||||
routes.push(req.route.path);
|
||||
next();
|
||||
});
|
||||
|
||||
assert.response(app,
|
||||
{ url: '/foo' },
|
||||
function(){
|
||||
routes.should.eql(['/:foo?', '/foo']);
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user