http-proxy-middleware
Advanced tools
Comparing version 0.8.0 to 0.8.1
13
index.js
@@ -20,10 +20,2 @@ var _ = require('lodash'); | ||
// handle option.pathRewrite | ||
if (pathRewriter) { | ||
var proxyReqPathRewrite = function (proxyReq, req, res, options) { | ||
proxyReq.path = pathRewriter(proxyReq.path); | ||
}; | ||
proxy.on('proxyReq', proxyReqPathRewrite); | ||
} | ||
// Custom listener for the `proxyRes` event on `proxy`. | ||
@@ -62,2 +54,7 @@ if (_.isFunction(proxyOptions.onProxyRes)) { | ||
if (contextMatcher.match(config.context, req.url)) { | ||
// handle option.pathRewrite | ||
if (pathRewriter) { | ||
req.url = pathRewriter(req.url); | ||
} | ||
if (proxyOptions.proxyTable) { | ||
@@ -64,0 +61,0 @@ // change option.target when proxyTable present. |
{ | ||
"name": "http-proxy-middleware", | ||
"version": "0.8.0", | ||
"version": "0.8.1", | ||
"description": "The one-liner node.js proxy middleware for connect, express and browser-sync", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
100
README.md
# http-proxy-middleware | ||
[![Build Status](https://img.shields.io/travis/chimurai/http-proxy-middleware/master.svg?style=flat-square)](https://travis-ci.org/chimurai/http-proxy-middleware) | ||
[![Coveralls](https://img.shields.io/coveralls/chimurai/http-proxy-middleware.svg?style=flat-square)](https://coveralls.io/r/chimurai/http-proxy-middleware) | ||
[![Codacy](https://img.shields.io/codacy/43dc1adc5e4b490ca84a1f447c13795a.svg?style=flat-square)](https://www.codacy.com/app/chimurai/http-proxy-middleware/dashboard) | ||
[![dependency Status](https://img.shields.io/david/chimurai/http-proxy-middleware.svg?style=flat-square)](https://david-dm.org/chimurai/http-proxy-middleware#info=dependencies) | ||
@@ -9,3 +11,4 @@ [![devDependency Status](https://img.shields.io/david/dev/chimurai/http-proxy-middleware.svg?style=flat-square)](https://david-dm.org/chimurai/http-proxy-middleware#info=devDependencies) | ||
### Install | ||
## Install | ||
```javascript | ||
@@ -15,3 +18,4 @@ $ npm install --save-dev http-proxy-middleware | ||
### Core concept | ||
## Core concept | ||
Configure the proxy middleware. | ||
@@ -41,4 +45,4 @@ ```javascript | ||
## Example | ||
### Example | ||
An example with express server. | ||
@@ -81,4 +85,4 @@ ```javascript | ||
## Context matching | ||
### Context matching | ||
http-proxy-middleware offers several ways to decide which requests should be proxied. | ||
@@ -88,20 +92,19 @@ Request URL's [ _path-absolute_ and _query_](https://tools.ietf.org/html/rfc3986#section-3) will be used for context matching . | ||
* **path matching** | ||
* `'/'` - matches any path, all requests will be proxied. | ||
* `'/api'` - matches paths starting with `/api` | ||
- `'/'` - matches any path, all requests will be proxied. | ||
- `'/api'` - matches paths starting with `/api` | ||
* **multiple path matching** | ||
* `['/api', '/ajax', '/someotherpath']` | ||
- `['/api', '/ajax', '/someotherpath']` | ||
* **wildcard path matching** | ||
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 paths directly under path-absolute | ||
- `'/api/**/*.html'` matches requests ending with `.html` in the path of `/api` | ||
- `['/api/**', '/ajax/**']` combine multiple patterns | ||
- `['/api/**', '!**/bad.json']` exclusion | ||
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 paths directly under path-absolute | ||
* `/api/**/*.html` matches requests ending with `.html` in the path of `/api` | ||
* `['/api/**', '/ajax/**']` combine multiple patterns | ||
* `['/api/**', '!**/bad.json']` exclusion | ||
## Shorthand | ||
### Shorthand | ||
Use the shorthand syntax when verbose configuration is not needed. The `context` and `option.target` will be automatically configured when shorthand is used. Options can still be used if needed. | ||
@@ -122,4 +125,4 @@ | ||
## WebSocket | ||
### WebSocket | ||
```javascript | ||
@@ -136,3 +139,4 @@ // verbose api | ||
#### External WebSocket upgrade | ||
### External WebSocket upgrade | ||
In the previous WebSocket examples, http-proxy-middleware relies on a initial http request in order to listen to the http `upgrade` event. If you need to proxy WebSockets without the initial http request, you can subscribe to the server's http `upgrade` event manually. | ||
@@ -149,4 +153,4 @@ ```javascript | ||
## Options | ||
### Options | ||
* **option.pathRewrite**: object, rewrite target's url path. Object-keys will be used as _RegExp_ to match paths. | ||
@@ -191,24 +195,24 @@ ```javascript | ||
The following options are provided by the underlying [http-proxy](https://www.npmjs.com/package/http-proxy). | ||
* **option.target**: url string to be parsed with the url module | ||
* **option.forward**: url string to be parsed with the url module | ||
* **option.agent**: object to be passed to http(s).request (see Node's [https agent](http://nodejs.org/api/https.html#https_class_https_agent) and [http agent](http://nodejs.org/api/http.html#http_class_http_agent) objects) | ||
* **option.secure**: true/false, if you want to verify the SSL Certs | ||
* **option.xfwd**: true/false, adds x-forward headers | ||
* **option.toProxy**: passes the absolute URL as the `path` (useful for proxying to proxies) | ||
* **option.hostRewrite**: rewrites the location hostname on (301/302/307/308) redirects. | ||
* **option.ssl**: object to be passed to https.createServer() | ||
* **option.ws: true/false**: if you want to proxy websockets | ||
Undocumented options are provided by the underlying [http-proxy](https://github.com/nodejitsu/node-http-proxy/blob/master/lib/http-proxy.js#L32). | ||
* **option.headers**: object, adds [request headers](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields). (Example: `{host:'www.example.org'}` | ||
* **option.changeOrigin**: true/false, adds host to request header. | ||
* **option.prependPath**: true/false, Default: true - specify whether you want to prepend the target's path to the proxy path> | ||
* **option.ignorePath**: true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request> | ||
* **option.localAddress** : Local interface string to bind for outgoing connections | ||
* **option.auth** : Basic authentication i.e. 'user:password' to compute an Authorization header. | ||
* **option.autoRewrite**: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false. | ||
* **option.protocolRewrite**: rewrites the location protocol on (301/302/307/308) redirects to 'http' or 'https'. Default: null. | ||
* **option.target**: url string to be parsed with the url module | ||
* **option.forward**: url string to be parsed with the url module | ||
* **option.agent**: object to be passed to http(s).request (see Node's [https agent](http://nodejs.org/api/https.html#https_class_https_agent) and [http agent](http://nodejs.org/api/http.html#http_class_http_agent) objects) | ||
* **option.ssl**: object to be passed to https.createServer() | ||
* **option.ws**: true/false: if you want to proxy websockets | ||
* **option.xfwd**: true/false, adds x-forward headers | ||
* **option.secure**: true/false, if you want to verify the SSL Certs | ||
* **option.toProxy**: passes the absolute URL as the `path` (useful for proxying to proxies) | ||
* **option.prependPath**: true/false, Default: true - specify whether you want to prepend the target's path to the proxy path> | ||
* **option.ignorePath**: true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request> | ||
* **option.localAddress** : Local interface string to bind for outgoing connections | ||
* **option.changeOrigin**: true/false, adds host to request header. | ||
* **option.auth** : Basic authentication i.e. 'user:password' to compute an Authorization header. | ||
* **option.hostRewrite**: rewrites the location hostname on (301/302/307/308) redirects. | ||
* **option.autoRewrite**: rewrites the location host/port on (301/302/307/308) redirects based on requested host/port. Default: false. | ||
* **option.protocolRewrite**: rewrites the location protocol on (301/302/307/308) redirects to 'http' or 'https'. Default: null. | ||
Undocumented options are provided by the underlying http-proxy | ||
* **option.headers**: object, adds [request headers](https://en.wikipedia.org/wiki/List_of_HTTP_header_fields#Request_fields). (Example: `{host:'www.example.org'}`) [source](https://github.com/nodejitsu/node-http-proxy/blob/master/examples/http/proxy-http-to-https.js#L41) | ||
### More Examples | ||
## More Examples | ||
@@ -230,9 +234,9 @@ To run and view the [proxy examples](https://github.com/chimurai/http-proxy-middleware/tree/master/examples), clone the http-proxy-middleware repo and install the dependencies: | ||
Or just explore the proxy examples' sources: | ||
* `examples/connect` - [connect proxy example](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/connect/index.js) | ||
* `examples/express` - [express proxy example](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/express/index.js) | ||
* `examples/browser-sync` - [browser-sync proxy example](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/browser-sync/index.js) | ||
* `examples/websocket` - [websocket proxy example](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/websocket/index.js) with express | ||
* `examples/connect` - [connect proxy example](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/connect/index.js) | ||
* `examples/express` - [express proxy example](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/express/index.js) | ||
* `examples/browser-sync` - [browser-sync proxy example](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/browser-sync/index.js) | ||
* `examples/websocket` - [websocket proxy example](https://github.com/chimurai/http-proxy-middleware/tree/master/examples/websocket/index.js) with express | ||
## Compatible servers | ||
### Compatible servers: | ||
http-proxy-middleware is compatible with the following servers: | ||
@@ -243,5 +247,4 @@ * [connect](https://www.npmjs.com/package/connect) | ||
## Tests | ||
### Tests | ||
To run the test suite, first install the dependencies, then run: | ||
@@ -257,3 +260,5 @@ | ||
### Changelog | ||
## Changelog | ||
* [v0.8.1](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.8.1) - fixed pathRewrite when `agent` is configured | ||
* [v0.8.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.8.0) - support external websocket upgrade, fixed websocket shorthand | ||
@@ -269,3 +274,4 @@ * [v0.7.0](https://github.com/chimurai/http-proxy-middleware/releases/tag/v0.7.0) - support shorthand syntax, fixed express/connect mounting | ||
### License: | ||
## License | ||
The MIT License (MIT) | ||
@@ -272,0 +278,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
82756
286
1483