Skip to content

Instantly share code, notes, and snippets.

@Korver2017
Last active August 19, 2019 07:09
Show Gist options
  • Select an option

  • Save Korver2017/465dbd81a866bfb58fae17c6dd79f2fe to your computer and use it in GitHub Desktop.

Select an option

Save Korver2017/465dbd81a866bfb58fae17c6dd79f2fe to your computer and use it in GitHub Desktop.

Revisions

  1. Korver2017 revised this gist Aug 19, 2019. 1 changed file with 18 additions and 18 deletions.
    36 changes: 18 additions & 18 deletions cors-proxy-2.js
    Original file line number Diff line number Diff line change
    @@ -1,21 +1,21 @@
    if (req.method === 'OPTIONS') {
    // CORS Preflight
    res.send();
    } else {
    // var targetURL = req.header('Target-URL');
    var targetURL = req.header('Target-Endpoint');
    // CORS Preflight
    res.send();
    } else {
    // var targetURL = req.header('Target-URL');
    var targetURL = req.header('Target-Endpoint');

    if (!targetURL) {
    res.send(500, { error: 'There is no Target-Endpoint header in the request' });
    return;
    }
    // request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': req.header('Authorization')} },
    request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': req.header('Target-Endpoint')} },
    if (!targetURL) {
    res.send(500, { error: 'There is no Target-Endpoint header in the request' });
    return;
    }
    // request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': req.header('Authorization')} },
    request({ url: targetURL + req.url, method: req.method, json: req.body, headers: { 'Authorization': req.header('Target-Endpoint') } },

    function (error, response, body) {
    if (error) {
    console.error('error: ' + response.statusCode)
    }
    // console.log(body);
    }).pipe(res);
    }
    function (error, response, body) {
    if (error) {
    console.error('error: ' + response.statusCode)
    }
    // console.log(body);
    }).pipe(res);
    }
  2. Korver2017 revised this gist Aug 17, 2019. 1 changed file with 1 addition and 3 deletions.
    4 changes: 1 addition & 3 deletions cors-proxy-2.js
    Original file line number Diff line number Diff line change
    @@ -2,17 +2,15 @@ if (req.method === 'OPTIONS') {
    // CORS Preflight
    res.send();
    } else {

    // var targetURL = req.header('Target-URL');
    var targetURL = req.header('Target-Endpoint');

    if (!targetURL) {
    res.send(500, { error: 'There is no Target-Endpoint header in the request' });
    return;
    }

    // request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': req.header('Authorization')} },
    request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': targetURL} },
    request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': req.header('Target-Endpoint')} },

    function (error, response, body) {
    if (error) {
  3. Korver2017 revised this gist Aug 16, 2019. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion cors-proxy-2.js
    Original file line number Diff line number Diff line change
    @@ -2,15 +2,16 @@ if (req.method === 'OPTIONS') {
    // CORS Preflight
    res.send();
    } else {

    // var targetURL = req.header('Target-URL');
    var targetURL = req.header('Target-Endpoint');

    if (!targetURL) {
    res.send(500, { error: 'There is no Target-Endpoint header in the request' });
    return;
    }

    // request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': req.header('Authorization')} },

    request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': targetURL} },

    function (error, response, body) {
  4. Korver2017 created this gist Aug 16, 2019.
    22 changes: 22 additions & 0 deletions cors-proxy-2.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,22 @@
    if (req.method === 'OPTIONS') {
    // CORS Preflight
    res.send();
    } else {
    // var targetURL = req.header('Target-URL');
    var targetURL = req.header('Target-Endpoint');

    if (!targetURL) {
    res.send(500, { error: 'There is no Target-Endpoint header in the request' });
    return;
    }
    // request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': req.header('Authorization')} },

    request({ url: targetURL + req.url, method: req.method, json: req.body, headers: {'Authorization': targetURL} },

    function (error, response, body) {
    if (error) {
    console.error('error: ' + response.statusCode)
    }
    // console.log(body);
    }).pipe(res);
    }