mirror of
https://github.com/d0zingcat/cors-anywhere.git
synced 2026-05-13 15:09:25 +00:00
Remove getHandler
It is not supported, and its current form was not documented. If you need to proxy a request without listening on a port, just dispatch a 'request' event on the return value of createServer().
This commit is contained in:
15
README.md
15
README.md
@@ -85,13 +85,8 @@ jQuery.ajaxPrefilter(function(options) {
|
||||
|
||||
### Server
|
||||
|
||||
The module exports two properties: `getHandler` and `createServer`.
|
||||
|
||||
* `getHandler(options)` returns a handler which implements the routing logic.
|
||||
This handler is used by [http-proxy](https://github.com/nodejitsu/node-http-proxy).
|
||||
* `createServer(options)` creates a server with the default handler.
|
||||
|
||||
The following options are recognized by both methods:
|
||||
The module exports `createServer(options)`, which creates a server that handles
|
||||
proxy requests. The following options are supported:
|
||||
|
||||
* function `getProxyForUrl` - If set, specifies which intermediate proxy to use for a given URL.
|
||||
If the return value is void, a direct request is sent. The default implementation is
|
||||
@@ -110,9 +105,11 @@ The following options are recognized by both methods:
|
||||
* dictionary of lowercase strings `setHeaders` - Set headers for the request (overwrites existing ones).
|
||||
Example: `{"x-powered-by": "CORS Anywhere"}`
|
||||
|
||||
`createServer` recognizes the following option as well:
|
||||
For advanced users, the following options are also provided.
|
||||
|
||||
* `httpProxyOptions` - Options for http-proxy. The documentation for these options can be found [here](https://github.com/nodejitsu/node-http-proxy#options).
|
||||
* `httpProxyOptions` - Under the hood, [http-proxy](https://github.com/nodejitsu/node-http-proxy)
|
||||
is used to proxy requests. Use this option if you really need to pass options
|
||||
to http-proxy. The documentation for these options can be found [here](https://github.com/nodejitsu/node-http-proxy#options).
|
||||
* `httpsOptions` - If set, a `https.Server` will be created. The given options are passed to the
|
||||
[`https.createServer`](https://nodejs.org/api/https.html#https_https_createserver_options_requestlistener) method.
|
||||
|
||||
|
||||
@@ -207,7 +207,7 @@ function parseURL(req_url) {
|
||||
}
|
||||
|
||||
// Request handler factory
|
||||
var getHandler = exports.getHandler = function(options, proxy) {
|
||||
function getHandler(options, proxy) {
|
||||
var corsAnywhere = {
|
||||
getProxyForUrl: getProxyForUrl, // Function that specifies the proxy to use
|
||||
maxRedirects: 5, // Maximum number of redirects to be followed.
|
||||
@@ -217,13 +217,13 @@ var getHandler = exports.getHandler = function(options, proxy) {
|
||||
removeHeaders: [], // Strip these request headers.
|
||||
setHeaders: {}, // Set these request headers.
|
||||
};
|
||||
if (options) {
|
||||
Object.keys(corsAnywhere).forEach(function(option) {
|
||||
if (Object.prototype.hasOwnProperty.call(options, option)) {
|
||||
corsAnywhere[option] = options[option];
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
Object.keys(corsAnywhere).forEach(function(option) {
|
||||
if (Object.prototype.hasOwnProperty.call(options, option)) {
|
||||
corsAnywhere[option] = options[option];
|
||||
}
|
||||
});
|
||||
|
||||
// Convert corsAnywhere.requireHeader to an array of lowercase header names, or null.
|
||||
if (corsAnywhere.requireHeader) {
|
||||
if (typeof corsAnywhere.requireHeader === 'string') {
|
||||
@@ -321,7 +321,7 @@ var getHandler = exports.getHandler = function(options, proxy) {
|
||||
|
||||
proxyRequest(req, res, proxy);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
||||
// Create server with default and given values
|
||||
// Creator still needs to call .listen()
|
||||
|
||||
Reference in New Issue
Block a user