http-proxy-middleware
Advanced tools
Comparing version 0.17.0-beta to 0.17.0
# Changelog | ||
## [develop](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.0) | ||
- fix(wildcard context matching): Use [RFC 3986 path](https://tools.ietf.org/html/rfc3986#section-3.3) in wildcard matching. (excludes query parameters) | ||
## [v0.17.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.17.0) | ||
- fix(context matching): Use [RFC 3986 path](https://tools.ietf.org/html/rfc3986#section-3.3) in context matching. (excludes query parameters) | ||
@@ -6,0 +6,0 @@ ## [v0.16.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.16.0) |
@@ -36,4 +36,4 @@ var _ = require('lodash'); | ||
if (_.isFunction(context)) { | ||
var path = getUrl(uri).path; | ||
return context(path, req); | ||
var pathname = getUrlPathName(uri); | ||
return context(pathname, req); | ||
} | ||
@@ -50,8 +50,8 @@ | ||
function matchSingleStringPath(context, uri) { | ||
var path = getUrl(uri).path; | ||
return path.indexOf(context) === 0; | ||
var pathname = getUrlPathName(uri); | ||
return pathname.indexOf(context) === 0; | ||
} | ||
function matchSingleGlobPath(pattern, uri) { | ||
var pathname = getUrl(uri).pathname; | ||
var pathname = getUrlPathName(uri); | ||
var matches = micromatch(pathname, pattern); | ||
@@ -80,4 +80,10 @@ return matches && (matches.length > 0); | ||
function getUrl(uri) { | ||
return uri && url.parse(uri); | ||
/** | ||
* Parses URI and returns RFC 3986 path | ||
* | ||
* @param {String} uri from req.url | ||
* @return {String} RFC 3986 path | ||
*/ | ||
function getUrlPathName(uri) { | ||
return uri && url.parse(uri).pathname; | ||
} | ||
@@ -84,0 +90,0 @@ |
{ | ||
"name": "http-proxy-middleware", | ||
"version": "0.17.0-beta", | ||
"version": "0.17.0", | ||
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -130,6 +130,16 @@ # http-proxy-middleware | ||
Providing an alternative way to decide which requests should be proxied; In case you are not able to use the server's [`path` parameter](http://expressjs.com/en/4x/api.html#app.use) to mount the proxy or when you need more flexibility. Request URL's [ _path-absolute_ and _query_](https://tools.ietf.org/html/rfc3986#section-3) will be used for context matching. | ||
Providing an alternative way to decide which requests should be proxied; In case you are not able to use the server's [`path` parameter](http://expressjs.com/en/4x/api.html#app.use) to mount the proxy or when you need more flexibility. | ||
The [RFC 3986 `path`](https://tools.ietf.org/html/rfc3986#section-3.3) is be used for context matching. | ||
``` | ||
foo://example.com:8042/over/there?name=ferret#nose | ||
\_/ \______________/\_________/ \_________/ \__/ | ||
| | | | | | ||
scheme authority path query fragment | ||
``` | ||
* **path matching** | ||
- `proxy({...})` or `proxy('/', {...})` - matches any path, all requests will be proxied. | ||
- `proxy({...})` - matches any path, all requests will be proxied. | ||
- `proxy('/', {...})` - matches any path, all requests will be proxied. | ||
- `proxy('/api', {...})` - matches paths starting with `/api` | ||
@@ -157,4 +167,4 @@ | ||
*/ | ||
var filter = function (path, req) { | ||
return (path.match('^/api') && req.method === 'GET'); | ||
var filter = function (pathname, req) { | ||
return (pathname.match('^/api') && req.method === 'GET'); | ||
}; | ||
@@ -161,0 +171,0 @@ |
# Context matching | ||
Determine which requests should be proxied. `http-proxy-middleware` offers several ways to do this: | ||
Determine which requests should be proxied. | ||
Context matching is optional and is useful in cases where you are not able to use the regular [middleware mounting](http://expressjs.com/en/4x/api.html#app.use). | ||
The [RFC 3986 `path`](https://tools.ietf.org/html/rfc3986#section-3.3) is used for context matching. | ||
``` | ||
foo://example.com:8042/over/there?name=ferret#nose | ||
\_/ \______________/\_________/ \_________/ \__/ | ||
| | | | | | ||
scheme authority path query fragment | ||
``` | ||
`http-proxy-middleware` offers several ways to do this: | ||
<!-- MarkdownTOC autolink=true bracket=round --> | ||
@@ -19,6 +33,4 @@ | ||
This example will create a basic proxy. | ||
This will match paths starting with `/api` | ||
Requests with path `/api` will be proxied to `http://localhost:3000` | ||
```javascript | ||
@@ -34,6 +46,4 @@ var proxy = require("http-proxy-middleware"); | ||
This example will create a basic proxy | ||
This will match paths starting with `/api` or `/rest` | ||
Requests with path `/api` and `/rest` will be proxied to `http://localhost:3000` | ||
```javascript | ||
@@ -50,3 +60,3 @@ var proxy = require("http-proxy-middleware"); | ||
This example will create a proxy with wildcard context matching. | ||
This will match paths starting with `/api/` and should also end with `.json` | ||
@@ -61,3 +71,3 @@ ```javascript | ||
This example will create a proxy with wildcard context matching. | ||
Multiple wildcards can be used. | ||
@@ -67,3 +77,3 @@ ```javascript | ||
var apiProxy = proxy(['/api/**', '/ajax/**'], {target: 'http://localhost:3000'}); | ||
var apiProxy = proxy(['/api/**/*.json', '/rest/**'], {target: 'http://localhost:3000'}); | ||
``` | ||
@@ -78,3 +88,3 @@ | ||
var apiProxy = proxy(['/api/**', '!**/bad.json'], {target: 'http://localhost:3000'}); | ||
var apiProxy = proxy(['foo/*.js', '!bar.js'], {target: 'http://localhost:3000'}); | ||
``` | ||
@@ -84,4 +94,4 @@ | ||
This example will create a proxy with custom filtering. | ||
The request `path` and `req` object are provided to determine which requests should be proxied or not. | ||
Write your custom context matching function to have full control on the matching behavior. | ||
The request `pathname` and `req` object are provided to determine which requests should be proxied or not. | ||
@@ -91,4 +101,4 @@ ```javascript | ||
var filter = function (path, req) { | ||
return (path.match('^/api') && req.method === 'GET'); | ||
var filter = function (pathname, req) { | ||
return (pathname.match('^/api') && req.method === 'GET'); | ||
}; | ||
@@ -95,0 +105,0 @@ |
Sorry, the diff of this file is not supported yet
160708
2432
433