From e6ef751eb707e2898bed65e23e88fa570123e87c Mon Sep 17 00:00:00 2001 From: Steven Chim Date: Sat, 25 Jul 2015 14:59:05 +0200 Subject: [PATCH] updated: micromatch dependency docs: fix incorrect glob usage --- README.md | 4 ++-- package.json | 4 ++-- test/context-matcher.spec.js | 23 +++++++++++++---------- test/http-proxy-middleware.spec.js | 2 +- 4 files changed, 18 insertions(+), 15 deletions(-) diff --git a/README.md b/README.md index b86c7869..a6f04b0b 100644 --- a/README.md +++ b/README.md @@ -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 diff --git a/package.json b/package.json index e624ebfa..8b8f9e76 100644 --- a/package.json +++ b/package.json @@ -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": { @@ -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" } } diff --git a/test/context-matcher.spec.js b/test/context-matcher.spec.js index cbe3a320..4482da0c 100644 --- a/test/context-matcher.spec.js +++ b/test/context-matcher.spec.js @@ -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 () { @@ -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 () { @@ -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; @@ -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; }); }); }); diff --git a/test/http-proxy-middleware.spec.js b/test/http-proxy-middleware.spec.js index c63eac99..b41f28dd 100644 --- a/test/http-proxy-middleware.spec.js +++ b/test/http-proxy-middleware.spec.js @@ -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