How to use Cors anywhere to cancel proxy and add CORS headers

I read the documentation of this reverse proxy for two hours to add CORS headers, and I cannot use. Can you help with a simple example of how to use this.

CORS EVERYWHERE

I tried this example in JavaScript

(function() {
var cors_api_host = 'cors-anywhere.herokuapp.com';
var cors_api_url = 'https://' + cors_api_host + '/';
var slice = [].slice;
var origin = window.location.protocol + '//' + window.location.host;
var open = XMLHttpRequest.prototype.open;
XMLHttpRequest.prototype.open = function() {
    var args = slice.call(arguments);
    var targetOrigin = /^https?:\/\/([^\/]+)/i.exec(args[1]);
    if (targetOrigin && targetOrigin[0].toLowerCase() !== origin &&
        targetOrigin[1] !== cors_api_host) {
        args[1] = cors_api_url + args[1];
    }
    return open.apply(this, args);
};
})();

I don’t understand if I really need node.js or what exactly

+7
source share
3 answers

CORS Anywhere helps with accessing data from other sites, which are usually prohibited by the same web browser policy. This is done by proxying requests to these sites through the server (in this case, it is recorded in Node.js).

" API, URL URL- API" .. . http://example.com https://cors-anywhere.herokuapp.com/http://example.com. CORS Anywhere CORS , - .

URL- , XMLHttpRequest, . , URL- API CORS Anywhere , -.

Github (https://github.com/Rob--W/cors-anywhere) , CORS Anywhere. , , . , CORS Anywhere, CORS Anywhere.

+18

, .

(, , CORS Anywhere. .)

  • Node.js.
  • CORS Anywhere.

    , :

    npm install cors-anywhere

    ( CORS Anywhere , node_modules\cors-anywhere.)

  • CORS Anywhere.

    , :

    node cors-anywhere.js

CORS Anywhere :

Running CORS Anywhere on 127.0.0.1:8080

(IP- 127.0.0.1 - localhost, .)

, cors-anywhere.js.

, -, CORS, URL-:

http://remote.server.com:8085/service

URL- CORS Anywhere, URL- :

http://localhost:8080/remote.server.com:8085/service

( http:// URL-.)

+12

: https://github.com/Zibri/cloudflare-cors-anywhere

You can make your own code in 3 minutes by downloading the code to the free cloudflare working tool!

0
source

Source: https://habr.com/ru/post/1669327/


All Articles