XXX-domain GET

    @@ -8,8 +8,9 @@ */ // c.f. -// https://crossorigin.me -// https://github.com/technoboy10/crossorigin.me +// https://robwu.nl/cors-anywhere.html +// https://cors-anywhere.herokuapp.com +// https://github.com/Rob--W/cors-anywhere/ (() => { 'use strict'; @@ -20,11 +21,14 @@ const TIMEOUT = 5000; const timer = setTimeout(() => controller.abort(), TIMEOUT); - // XXX this server down/glitch so often - const PROXY = 'https://crossorigin.me/'; + const PROXY = 'https://cors-anywhere.herokuapp.com/'; const url = 'https://example.com'; - fetch(PROXY + url, { + + // https://github.com/Rob--W/cors-anywhere/#example + // `:443` not in use? + //fetch(PROXY + url + new URL(url).protocol === 'https' ? ':443' : '', { + fetch(PROXY + url , { mode: 'cors', signal, })
  • /*
     * @title XXX-domain GET
     * @description XXX cross-domain GET over CORS abstract
     * @include http://*
     * @include https://*
     * @license MIT License https://opensource.org/licenses/MIT
     * @javascript_url
     */
    
    // c.f.
    // https://robwu.nl/cors-anywhere.html
    // https://cors-anywhere.herokuapp.com
    //  https://github.com/Rob--W/cors-anywhere/
    (() => {
        'use strict';
    
        // timeout
        // https://gist.github.com/noromanba/7e76cd75d15e27b102007298a8156d8f
        const controller = new AbortController();
        const signal = controller.signal;
        const TIMEOUT = 5000;
        const timer = setTimeout(() => controller.abort(), TIMEOUT);
    
        const PROXY = 'https://cors-anywhere.herokuapp.com/';
    
        const url = 'https://example.com';
    
        // https://github.com/Rob--W/cors-anywhere/#example
        // `:443` not in use?
        //fetch(PROXY + url + new URL(url).protocol === 'https' ? ':443' : '', {
        fetch(PROXY + url , {
            mode: 'cors',
            signal,
        })
        .then(res => {
            if (!res.ok) {
                return Promise.reject(new Error(res.status, res.statusText));
            }
            return res.text();
        })
        .then(data => {
            // do something
            console.dir(data);
            return data;
        })
        .catch(err => {
            console.warn(err.message, err);
        })
        .finally(() => {
            clearTimeout(timer);
            console.log('settled');
        });
    })();
    
    
    
  • Permalink
    このページへの個別リンクです。
    RAW
    書かれたコードへの直接のリンクです。
    Packed
    文字列が圧縮された書かれたコードへのリンクです。
    Userscript
    Greasemonkey 等で利用する場合の .user.js へのリンクです。
    Loader
    @require やソースコードが長い場合に多段ロードする Loader コミのコードへのリンクです。
    Metadata
    コード中にコメントで @xxx と書かれたメタデータの JSON です。

History

  1. 2018/05/30 07:34:14 - 2018-05-30
  2. 2018/05/19 15:25:35 - 2018-05-19
  3. 2018/05/19 14:57:15 - 2018-05-19
  4. 2018/05/19 14:29:10 - 2018-05-19
  5. 2018/05/19 14:28:10 - 2018-05-19
  6. 2018/05/18 22:14:19 - 2018-05-18
  7. 2018/05/18 22:13:39 - 2018-05-18
  8. 2018/05/18 22:04:11 - 2018-05-18
  9. 2018/05/18 21:54:42 - 2018-05-18