1 | [![Build Status](https://secure.travis-ci.org/superjoe30/connect-proxy.png)](http://travis-ci.org/superjoe30/connect-proxy)
|
2 |
|
3 | ### Usage:
|
4 |
|
5 | ```js
|
6 | var connect = require('connect')
|
7 | , url = require('url')
|
8 | , proxy = require('proxy-middleware')
|
9 |
|
10 | var app = connect();
|
11 | app.use('/api', proxy(url.parse('https://example.com/endpoint')));
|
12 | // now requests to '/api/x/y/z' are proxied to 'https://example.com/endpoint/x/y/z'
|
13 | ```
|
14 |
|
15 | ### Documentation:
|
16 |
|
17 | `proxyMiddleware(options)`
|
18 |
|
19 | `options` allows any options that are permitted on the [`http`](http://nodejs.org/api/http.html#http_http_request_options_callback) or [`https`](http://nodejs.org/api/https.html#https_https_request_options_callback) request options.
|
20 |
|
21 | Other options:
|
22 | - `route`: you can pass the route for connect middleware within the options, as well.
|
23 |
|
24 | ### Usage with route:
|
25 |
|
26 | ```js
|
27 | var proxyOptions = url.parse('https://example.com/endpoint');
|
28 | proxyOptions.route = '/api';
|
29 |
|
30 | var middleWares = [proxy(proxyOptions) /*, ...*/];
|
31 |
|
32 | // Grunt connect uses this method
|
33 | connect(middleWares);
|
34 | ```
|