Skip to content

Commit

Permalink
Merge branch 'master' of github.com:visionmedia/express
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Feb 18, 2012
2 parents f8a9cbe + 15f2e0c commit 3360613
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 8 deletions.
6 changes: 4 additions & 2 deletions lib/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ var connect = require('connect')
, Router = require('./router')
, methods = Router.methods.concat('del', 'all')
, middleware = require('./middleware')
, debug = require('debug')('express:application')
, View = require('./view')
, url = require('url')
, utils = connect.utils
, path = require('path')
, http = require('http')
, join = path.join
, fs = require('fs')
, qs = require('qs');
, fs = require('fs');

/**
* Application prototype.
Expand Down Expand Up @@ -72,6 +72,7 @@ app.defaultConfiguration = function(){

// default settings
this.set('env', process.env.NODE_ENV || 'development');
debug('booting in %s mode', this.get('env'));

// implicit middleware
this.use(connect.query());
Expand Down Expand Up @@ -175,6 +176,7 @@ app.use = function(route, fn){
};
}

debug('use %s %s', route, fn.name || 'unnamed');
connect.proto.use.call(this, route, fn);

// mounted an app
Expand Down
5 changes: 5 additions & 0 deletions lib/router/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
var Route = require('./route')
, Collection = require('./collection')
, utils = require('../utils')
, debug = require('debug')('express:routes')
, parse = require('url').parse;

/**
Expand Down Expand Up @@ -200,6 +201,8 @@ Router.prototype._dispatch = function(req, res, next){
var params = this.params
, self = this;

debug('dispatching %s %s', req.method, req.url);

// route dispatch
(function pass(i, err){
var paramCallbacks
Expand All @@ -223,6 +226,7 @@ Router.prototype._dispatch = function(req, res, next){

// no route
if (!route) return next(err);
debug('matched %s %s', route.method, route.path);

// we have a route
// start at param 0
Expand Down Expand Up @@ -404,6 +408,7 @@ Router.prototype.route = function(method, path, callbacks){
if (!path) throw new Error('Router#' + method + '() requires a path');

// create the route
debug('defined %s %s', method, path);
var route = new Route(method, path, callbacks, {
sensitive: this.caseSensitive
, strict: this.strict
Expand Down
5 changes: 3 additions & 2 deletions lib/router/route.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

/*!
* Express - router - Route
* Copyright(c) 2010 TJ Holowaychuk <[email protected]>
Expand Down Expand Up @@ -59,7 +58,7 @@ Route.prototype.match = function(path){
* key names. For example "/user/:id" will
* then contain ["id"].
*
* @param {String|RegExp} path
* @param {String|RegExp|Array} path
* @param {Array} keys
* @param {Boolean} sensitive
* @param {Boolean} strict
Expand All @@ -69,6 +68,8 @@ Route.prototype.match = function(path){

function normalize(path, keys, sensitive, strict) {
if (path instanceof RegExp) return path;
if (path instanceof Array)
path = '(' + path.join('|') + ')';
path = path
.concat(strict ? '' : '/?')
.replace(/\/\(/g, '(?:/')
Expand Down
6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,9 @@
"dependencies": {
"connect": "git://github.com/senchalabs/connect.git",
"commander": "0.5.1",
"mime": ">= 1.2.4",
"qs": ">= 0.4.0",
"mkdirp": "0.2.2"
"mime": "1.2.4",
"mkdirp": "0.3.0",
"debug": "*"
},
"devDependencies": {
"ejs": "*",
Expand Down
19 changes: 18 additions & 1 deletion test/app.router.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

var express = require('../')
, request = require('./support/http')
, assert = require('assert');
Expand Down Expand Up @@ -110,6 +109,24 @@ describe('app.router', function(){
.expect('editing user 10', done);
})
})

describe('when given an array', function(){
it('should match all paths in the array', function(done){
var app = express();

app.get(['/one', '/two'], function(req, res){
res.end('works');
});

request(app)
.get('/one')
.expect('works', function() {
request(app)
.get('/two')
.expect('works', done);
});
})
})

describe('case sensitivity', function(){
it('should be disabled by default', function(done){
Expand Down

0 comments on commit 3360613

Please sign in to comment.