Add handleInitialRequest option to support #301

The custom filtering logic is not part of the public repository, to
keep the project clean.
This commit is contained in:
Rob Wu
2021-02-01 22:20:35 +01:00
parent 528ad7109f
commit 9f1af82434
3 changed files with 55 additions and 0 deletions

View File

@@ -256,6 +256,7 @@ function parseURL(req_url) {
// Request handler factory
function getHandler(options, proxy) {
var corsAnywhere = {
handleInitialRequest: null, // Function that may handle the request instead, by returning a truthy value.
getProxyForUrl: getProxyForUrl, // Function that specifies the proxy to use
maxRedirects: 5, // Maximum number of redirects to be followed.
originBlacklist: [], // Requests from these origins will be blocked.
@@ -310,6 +311,10 @@ function getHandler(options, proxy) {
var location = parseURL(req.url.slice(1));
if (corsAnywhere.handleInitialRequest && corsAnywhere.handleInitialRequest(req, res, location)) {
return;
}
if (!location) {
// Invalid API call. Show how to correctly use the API
showUsage(corsAnywhere.helpFile, cors_headers, res);