mirror of
https://github.com/d0zingcat/cors-anywhere.git
synced 2026-06-05 23:16:47 +00:00
Docs update, added CORS to some responses.
This commit is contained in:
@@ -7,19 +7,20 @@ var regexp_tld = require('./regexp-top-level-domain');
|
||||
|
||||
var help_file = __dirname + '/help.txt';
|
||||
var help_text;
|
||||
function showUsage(res) {
|
||||
function showUsage(headers, response) {
|
||||
headers['content-type'] = 'text/plain';
|
||||
if (help_text != null) {
|
||||
res.writeHead(200, {'content-type': 'text/plain'});
|
||||
res.end(help_text);
|
||||
response.writeHead(200, headers);
|
||||
response.end(help_text);
|
||||
} else {
|
||||
require('fs').readFile(help_file, 'utf8', function(err, data) {
|
||||
if (err) {
|
||||
console.error(err);
|
||||
res.writeHead(500, {});
|
||||
res.end();
|
||||
response.writeHead(500, headers);
|
||||
response.end();
|
||||
} else {
|
||||
help_text = data;
|
||||
showUsage(res); // Recursive call, but since data is a string, the recursion will end
|
||||
showUsage(headers, response); // Recursive call, but since data is a string, the recursion will end
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -92,7 +93,7 @@ var getHandler = exports.getHandler = function(options) {
|
||||
// 2:host
|
||||
if (!match || (match[2].indexOf('.') === -1 && match[2].indexOf(':') === -1) || match[4] > 65535) {
|
||||
// Incorrect usage. Show how to do it correctly.
|
||||
showUsage(res);
|
||||
showUsage(cors_headers, res);
|
||||
return;
|
||||
} else if (match[2] === 'iscorsneeded') {
|
||||
// Is CORS needed? This path is provided so that API consumers can test whether it's necessary
|
||||
@@ -112,7 +113,7 @@ var getHandler = exports.getHandler = function(options) {
|
||||
res.end();
|
||||
return;
|
||||
} else if (corsAnywhere.requireHeader != null && req.headers[corsAnywhere.requireHeader.toLowerCase()] == null) {
|
||||
res.writeHead(400, {'Content-Type': 'text/plain'});
|
||||
res.writeHead(400, cors_headers);
|
||||
res.end('Missing ' + corsAnywhere.requireHeader + ' header!');
|
||||
return;
|
||||
} else {
|
||||
|
||||
@@ -1,3 +1,5 @@
|
||||
This API enables cross-origin requests to anywhere.
|
||||
|
||||
Usage:
|
||||
|
||||
/ Shows help
|
||||
@@ -6,3 +8,5 @@ Usage:
|
||||
|
||||
The protocol can be omitted. It defaults to http:, unless port 443 is specified.
|
||||
|
||||
Demo : http://rob.lekensteyn.nl/cors-anywhere.html
|
||||
Source code : https://github.com/Rob--W/cors-anywhere/
|
||||
|
||||
Reference in New Issue
Block a user