Skip to content

Commit

Permalink
updated: micromatch dependency
Browse files Browse the repository at this point in the history
docs: fix incorrect glob usage
  • Loading branch information
chimurai committed Jul 25, 2015
1 parent bcb949b commit e6ef751
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 15 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -114,9 +114,9 @@ http-proxy-middleware offers several ways to decide which requests should be pro

For fine-grained control you can use wildcard matching. Glob pattern matching is done by _micromatch_. Visit [micromatch](https://www.npmjs.com/package/micromatch) or [glob](https://www.npmjs.com/package/glob) for more globbing examples.
* `**` matches any path, all requests will be proxied.
* `**.html` matches any path which ends with `.html`
* `**/*.html` matches any path which ends with `.html`
* `/*.html` matches paths directly under path-absolute
* `/api/**.html` matches requests ending with `.html` in the path of `/api`
* `/api/**/*.html` matches requests ending with `.html` in the path of `/api`
* `['/api/**', '/ajax/**']` combine multiple patterns
* `['/api/**', '!**/bad.json']` exclusion

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "http-proxy-middleware",
"version": "0.3.1",
"version": "0.3.2",
"description": "The one-liner proxy middleware for connect, express and browser-sync",
"main": "index.js",
"scripts": {
Expand Down Expand Up @@ -42,7 +42,7 @@
"dependencies": {
"http-proxy": "^1.11.1",
"is-glob": "^2.0.0",
"micromatch": "~2.1.6",
"micromatch": "^2.2.0",
"url": "^0.10.3"
}
}
23 changes: 13 additions & 10 deletions test/context-matcher.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,17 +82,20 @@ describe('Wildcard path matching', function () {
describe('file matching', function () {
it('should match any path, file and extension', function () {
expect(contextMatcher.match('**', url)).to.be.true;
expect(contextMatcher.match('**/*', url)).to.be.true;
expect(contextMatcher.match('**/*.*', url)).to.be.true;
expect(contextMatcher.match('/**', url)).to.be.true;
expect(contextMatcher.match('**.*', url)).to.be.true;
expect(contextMatcher.match('/**.*', url)).to.be.true;
expect(contextMatcher.match('**/*.*', url)).to.be.true;
expect(contextMatcher.match('/**/*', url)).to.be.true;
expect(contextMatcher.match('/**/*.*', url)).to.be.true;
});

it('should only match .html files', function () {
expect(contextMatcher.match('**.html', url)).to.be.true;
expect(contextMatcher.match('**.htm', url)).to.be.false;
expect(contextMatcher.match('**.jpg', url)).to.be.false;
expect(contextMatcher.match('**/*.html', url)).to.be.true;
expect(contextMatcher.match('/**.html', url)).to.be.true;
expect(contextMatcher.match('/**/*.html', url)).to.be.true;
expect(contextMatcher.match('/**.htm', url)).to.be.false;
expect(contextMatcher.match('/**.jpg', url)).to.be.false;
});

it('should only match .html under root path', function () {
Expand All @@ -102,8 +105,8 @@ describe('Wildcard path matching', function () {
});

it('should only match .php files with query params', function () {
expect(contextMatcher.match('**.php', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.false;
expect(contextMatcher.match('**.php?*', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.true;
expect(contextMatcher.match('/**/*.php', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.false;
expect(contextMatcher.match('/**/*.php?*', 'http://localhost/a/b/c.php?d=e&e=f')).to.be.true;
});

it('should only match any file in root path', function () {
Expand Down Expand Up @@ -134,7 +137,7 @@ describe('Wildcard path matching', function () {
expect(contextMatcher.match(pattern, 'http://localhost/rest/foo/bar.json')).to.be.false;
});
it('should return true when both file extensions pattern match', function () {
var pattern = ['**.html','**.jpeg'];
var pattern = ['/**.html','/**.jpeg'];
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.html')).to.be.true;
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.jpeg')).to.be.true;
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.gif')).to.be.false;
Expand All @@ -144,8 +147,8 @@ describe('Wildcard path matching', function () {
describe('Negation patterns', function () {
it('should not match file extension', function () {
var url = 'http://localhost/api/foo/bar.html';
expect(contextMatcher.match(['**', '!**.html'], url)).to.be.false;
expect(contextMatcher.match(['**', '!**.json'], url)).to.be.true;
expect(contextMatcher.match(['**', '!**/*.html'], url)).to.be.false;
expect(contextMatcher.match(['**', '!**/*.json'], url)).to.be.true;
});
});
});
Expand Down
2 changes: 1 addition & 1 deletion test/http-proxy-middleware.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ describe('http-proxy-middleware in actual server', function () {
var responseB, responseBodyB;

beforeEach(function () {
var mw_proxy = proxyMiddleware(['**.html', '!**.json'], {target:'http://localhost:8000'});
var mw_proxy = proxyMiddleware(['/**.html', '!**.json'], {target:'http://localhost:8000'});

var mw_target = function (req, res, next) {
res.write(req.url); // respond with req.url
Expand Down

0 comments on commit e6ef751

Please sign in to comment.