You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Node.js proxying made simple. Configure proxy middleware with ease for [connect](https://github.com/senchalabs/connect), [express](https://github.com/strongloop/express) and [browser-sync](https://github.com/BrowserSync/browser-sync).
7
+
Node.js proxying made simple. Configure proxy middleware with ease for [connect](https://github.com/senchalabs/connect), [express](https://github.com/strongloop/express), [browser-sync](https://github.com/BrowserSync/browser-sync) and [many more](#compatible-servers).
9
8
10
9
Powered by the popular Nodejitsu [`http-proxy`](https://github.com/nodejitsu/node-http-proxy). [](https://github.com/nodejitsu/node-http-proxy)
var context ='/api'; // requests with this path will be proxied
74
+
// use Array for multipath: ['/api', '/rest']
54
75
55
76
// configure proxy middleware options
56
77
var options = {
@@ -69,21 +90,19 @@ var options = {
69
90
};
70
91
71
92
// create the proxy
72
-
varproxy=proxyMiddleware(context, options);
93
+
varapiProxy=proxy(context, options);
73
94
74
-
// use the configured `proxy` in web server
95
+
// use the configured `apiProxy` in web server
75
96
var app =express();
76
-
app.use(proxy);
97
+
app.use(apiProxy);
77
98
app.listen(3000);
78
99
```
79
100
80
-
Check out [working examples](#more-examples).
81
-
82
101
**Tip:** For [name-based virtual hosted sites](http://en.wikipedia.org/wiki/Virtual_hosting#Name-based), you'll need to use the option `changeOrigin` and set it to `true`.
83
102
84
103
## Context matching
85
104
86
-
http-proxy-middleware offers several ways to decide which requests should be proxied.
105
+
`http-proxy-middleware` offers several ways to decide which requests should be proxied.
87
106
Request URL's [_path-absolute_ and _query_](https://tools.ietf.org/html/rfc3986#section-3) will be used for context matching .
88
107
89
108
***path matching**
@@ -111,50 +130,50 @@ Request URL's [ _path-absolute_ and _query_](https://tools.ietf.org/html/rfc3986
var apiProxy =proxyMiddleware(filter, {target:'http://www.example.org'})
133
+
var apiProxy =proxy(filter, {target:'http://www.example.org'})
115
134
```
116
135
117
136
## Shorthand
118
137
119
138
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.
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.
150
169
```javascript
151
-
var proxy = proxyMiddleware('ws://echo.websocket.org', {changeOrigin:true});
170
+
var wsProxy = proxy('ws://echo.websocket.org', {changeOrigin:true});
152
171
153
172
var app =express();
154
-
app.use(proxy);
173
+
app.use(wsProxy);
155
174
156
175
var server =app.listen(3000);
157
-
server.on('upgrade', proxy.upgrade);// <-- subscribe to http 'upgrade'
176
+
server.on('upgrade', wsProxy.upgrade); // <-- subscribe to http 'upgrade'
158
177
```
159
178
160
179
## Options
@@ -174,14 +193,14 @@ var server = app.listen(3000);
174
193
***option.proxyTable**: object, re-target `option.target` based on the request header `host` parameter. `host` can be used in conjunction with`path`. Only one instance of the proxy will be used. The order of the configuration matters.
175
194
```javascript
176
195
proxyTable: {
177
-
"integration.localhost:3000" : "http://localhost:8001", // host only
178
-
"staging.localhost:3000" : "http://localhost:8002", // host only
View the [recipes](https://github.com/chimurai/http-proxy-middleware/tree/master/recipes) for common use cases.
303
+
## Working examples
287
304
288
-
## More Examples
289
-
290
-
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:
View working examples of `http-proxy-middleware` implemented in popular servers.
4
+
5
+
To run and view the [examples](https://github.com/chimurai/http-proxy-middleware/tree/master/examples); Clone the `http-proxy-middleware` repo and install the dependencies:
You can find more server implementations with `http-proxy-middleware` in the [server recipes](https://github.com/chimurai/http-proxy-middleware/tree/master/recipes/servers.md)
0 commit comments