Skip to content

Commit e6ef751

Browse files
committed
updated: micromatch dependency
docs: fix incorrect glob usage
1 parent bcb949b commit e6ef751

File tree

4 files changed

+18
-15
lines changed

4 files changed

+18
-15
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -114,9 +114,9 @@ http-proxy-middleware offers several ways to decide which requests should be pro
114114
115115
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.
116116
* `**` matches any path, all requests will be proxied.
117-
* `**.html` matches any path which ends with `.html`
117+
* `**/*.html` matches any path which ends with `.html`
118118
* `/*.html` matches paths directly under path-absolute
119-
* `/api/**.html` matches requests ending with `.html` in the path of `/api`
119+
* `/api/**/*.html` matches requests ending with `.html` in the path of `/api`
120120
* `['/api/**', '/ajax/**']` combine multiple patterns
121121
* `['/api/**', '!**/bad.json']` exclusion
122122

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "http-proxy-middleware",
3-
"version": "0.3.1",
3+
"version": "0.3.2",
44
"description": "The one-liner proxy middleware for connect, express and browser-sync",
55
"main": "index.js",
66
"scripts": {
@@ -42,7 +42,7 @@
4242
"dependencies": {
4343
"http-proxy": "^1.11.1",
4444
"is-glob": "^2.0.0",
45-
"micromatch": "~2.1.6",
45+
"micromatch": "^2.2.0",
4646
"url": "^0.10.3"
4747
}
4848
}

test/context-matcher.spec.js

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -82,17 +82,20 @@ describe('Wildcard path matching', function () {
8282
describe('file matching', function () {
8383
it('should match any path, file and extension', function () {
8484
expect(contextMatcher.match('**', url)).to.be.true;
85+
expect(contextMatcher.match('**/*', url)).to.be.true;
86+
expect(contextMatcher.match('**/*.*', url)).to.be.true;
8587
expect(contextMatcher.match('/**', url)).to.be.true;
86-
expect(contextMatcher.match('**.*', url)).to.be.true;
8788
expect(contextMatcher.match('/**.*', url)).to.be.true;
88-
expect(contextMatcher.match('**/*.*', url)).to.be.true;
89+
expect(contextMatcher.match('/**/*', url)).to.be.true;
8990
expect(contextMatcher.match('/**/*.*', url)).to.be.true;
9091
});
9192

9293
it('should only match .html files', function () {
93-
expect(contextMatcher.match('**.html', url)).to.be.true;
94-
expect(contextMatcher.match('**.htm', url)).to.be.false;
95-
expect(contextMatcher.match('**.jpg', url)).to.be.false;
94+
expect(contextMatcher.match('**/*.html', url)).to.be.true;
95+
expect(contextMatcher.match('/**.html', url)).to.be.true;
96+
expect(contextMatcher.match('/**/*.html', url)).to.be.true;
97+
expect(contextMatcher.match('/**.htm', url)).to.be.false;
98+
expect(contextMatcher.match('/**.jpg', url)).to.be.false;
9699
});
97100

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

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

109112
it('should only match any file in root path', function () {
@@ -134,7 +137,7 @@ describe('Wildcard path matching', function () {
134137
expect(contextMatcher.match(pattern, 'http://localhost/rest/foo/bar.json')).to.be.false;
135138
});
136139
it('should return true when both file extensions pattern match', function () {
137-
var pattern = ['**.html','**.jpeg'];
140+
var pattern = ['/**.html','/**.jpeg'];
138141
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.html')).to.be.true;
139142
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.jpeg')).to.be.true;
140143
expect(contextMatcher.match(pattern, 'http://localhost/api/foo/bar.gif')).to.be.false;
@@ -144,8 +147,8 @@ describe('Wildcard path matching', function () {
144147
describe('Negation patterns', function () {
145148
it('should not match file extension', function () {
146149
var url = 'http://localhost/api/foo/bar.html';
147-
expect(contextMatcher.match(['**', '!**.html'], url)).to.be.false;
148-
expect(contextMatcher.match(['**', '!**.json'], url)).to.be.true;
150+
expect(contextMatcher.match(['**', '!**/*.html'], url)).to.be.false;
151+
expect(contextMatcher.match(['**', '!**/*.json'], url)).to.be.true;
149152
});
150153
});
151154
});

test/http-proxy-middleware.spec.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ describe('http-proxy-middleware in actual server', function () {
205205
var responseB, responseBodyB;
206206

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

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

0 commit comments

Comments
 (0)