Skip to content

CORS Anywhere is a NodeJS reverse proxy which adds CORS headers to the proxied request.

Notifications You must be signed in to change notification settings

francotc/cors-anywhere-zondafog

 
 

Repository files navigation

CORS Anywhere is a NodeJS proxy which adds CORS headers to the proxied request.

The url to proxy is literally taken from the path, validated and proxied. The protocol part of the proxied URI is optional, and defaults to "http". If port 443 is specified, the protocol defaults to "https".

This package does not put any restrictions on the http methods or headers, except for cookies. Requesting user credentials is disallowed. The app can be configured to require a header for proxying a request, for example to avoid a direct visit from the browser.

Server

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.
  • array of strings originBlacklist - If set, requests whose origin is listed are blocked.
    Example: ['https://bad.example.com', 'http://bad.example.com']
  • array of strings originWhitelist - If set, requests whose origin is not listed are blocked.
    If this list is empty, all origins are allowed. Example: ['https://good.example.com', 'http://good.example.com']
  • function checkRateLimit - If set, it is called with the origin (string) of the request. If this function returns a non-empty string, the request is rejected and the string is send to the client.
  • boolean redirectSameOrigin - If true, requests to URLs from the same origin will not be proxied but redirected. The primary purpose for this option is to save server resources by delegating the request to the client (since same-origin requests should always succeed, even without proxying).
  • array of strings requireHeader - If set, the request must include this header or the API will refuse to proxy.
    Recommended if you want to prevent users from using the proxy for normal browsing.
    Example: ['Origin', 'X-Requested-With'].
  • array of lowercase strings removeHeaders - Exclude certain headers from being included in the request.
    Example: ["cookie"]
  • dictionary of lowercase strings setHeaders - Set headers for the request (overwrites existing ones).
    Example: {"x-powered-by": "CORS Anywhere"}
  • number corsMaxAge - If set, an Access-Control-Max-Age request header with this value (in seconds) will be added.
    Example: 600 - Allow CORS preflight request to be cached by the browser for 10 minutes.
  • string helpFile - Set the help file (shown at the homepage).
    Example: "myCustomHelpText.txt"

For advanced users, the following options are also provided.

  • httpProxyOptions - Under the hood, 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.
  • httpsOptions - If set, a https.Server will be created. The given options are passed to the https.createServer method.

For even more advanced usage (building upon CORS Anywhere), see the sample code in test/test-examples.js.

License

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

CORS Anywhere is a NodeJS reverse proxy which adds CORS headers to the proxied request.

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 96.9%
  • HTML 3.1%