1
|
// Use explicit /index.js to help browserify negociation in require '/lib/http-proxy' (!)
|
2
|
var ProxyServer = require('./http-proxy/index.js').Server;
|
3
|
|
4
|
|
5
|
/**
|
6
|
* Creates the proxy server.
|
7
|
*
|
8
|
* Examples:
|
9
|
*
|
10
|
* httpProxy.createProxyServer({ .. }, 8000)
|
11
|
* // => '{ web: [Function], ws: [Function] ... }'
|
12
|
*
|
13
|
* @param {Object} Options Config object passed to the proxy
|
14
|
*
|
15
|
* @return {Object} Proxy Proxy object with handlers for `ws` and `web` requests
|
16
|
*
|
17
|
* @api public
|
18
|
*/
|
19
|
|
20
|
|
21
|
function createProxyServer(options) {
|
22
|
/*
|
23
|
* `options` is needed and it must have the following layout:
|
24
|
*
|
25
|
* {
|
26
|
* target : <url string to be parsed with the url module>
|
27
|
* forward: <url string to be parsed with the url module>
|
28
|
* agent : <object to be passed to http(s).request>
|
29
|
* ssl : <object to be passed to https.createServer()>
|
30
|
* ws : <true/false, if you want to proxy websockets>
|
31
|
* xfwd : <true/false, adds x-forward headers>
|
32
|
* secure : <true/false, verify SSL certificate>
|
33
|
* toProxy: <true/false, explicitly specify if we are proxying to another proxy>
|
34
|
* prependPath: <true/false, Default: true - specify whether you want to prepend the target's path to the proxy path>
|
35
|
* ignorePath: <true/false, Default: false - specify whether you want to ignore the proxy path of the incoming request>
|
36
|
* localAddress : <Local interface string to bind for outgoing connections>
|
37
|
* changeOrigin: <true/false, Default: false - changes the origin of the host header to the target URL>
|
38
|
* preserveHeaderKeyCase: <true/false, Default: false - specify whether you want to keep letter case of response header key >
|
39
|
* auth : Basic authentication i.e. 'user:password' to compute an Authorization header.
|
40
|
* hostRewrite: rewrites the location hostname on (201/301/302/307/308) redirects, Default: null.
|
41
|
* autoRewrite: rewrites the location host/port on (201/301/302/307/308) redirects based on requested host/port. Default: false.
|
42
|
* protocolRewrite: rewrites the location protocol on (201/301/302/307/308) redirects to 'http' or 'https'. Default: null.
|
43
|
* }
|
44
|
*
|
45
|
* NOTE: `options.ws` and `options.ssl` are optional.
|
46
|
* `options.target and `options.forward` cannot be
|
47
|
* both missing
|
48
|
* }
|
49
|
*/
|
50
|
|
51
|
return new ProxyServer(options);
|
52
|
}
|
53
|
|
54
|
|
55
|
ProxyServer.createProxyServer = createProxyServer;
|
56
|
ProxyServer.createServer = createProxyServer;
|
57
|
ProxyServer.createProxy = createProxyServer;
|
58
|
|
59
|
|
60
|
|
61
|
|
62
|
/**
|
63
|
* Export the proxy "Server" as the main export.
|
64
|
*/
|
65
|
module.exports = ProxyServer;
|
66
|
|