question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Access-Control-Allow-Origin workaround

See original GitHub issue

I an trying to to a simple get request, and I get an Access-Control-Allow-Origin error

Vue.http.get('https://some_url').then(response => {
      console.log(response);
}, response => {
      console.log(response);
});

If I do a regular xhr request, I don’t get the error and all is good

  let createCORSRequest = function (method, url) {
      let xhr = new XMLHttpRequest();
      if ("withCredentials" in xhr) {
        xhr.open(method, url, true);
      } else if (typeof XDomainRequest !== "undefined") {
        xhr = new XDomainRequest();
        xhr.open(method, url);
      } else {
        xhr = null;
      }
      return xhr;
    };

    let xhr = createCORSRequest('GET', 'https://some_url');

    xhr.onload = function () {
      console.log(JSON.parse(this.responseText));
    };

    xhr.onerror = function () {};

If I try to do a jsonp request instead, I get Uncaught SyntaxError: Unexpected token :, basically failing to parse the json response.

Vue.http.get('https://some_url').then(response => {
      console.log(response);
}, response => {
      console.log(response);
});

Any ideas?

Issue Analytics

  • State:open
  • Created 5 years ago
  • Comments:5

github_iconTop GitHub Comments

2reactions
jwauslecommented, Jul 20, 2019

Enables cross-origin requests to anywhere via proxy.

let xhr = createCORSRequest('GET', 'https://cors-anywhere.herokuapp.com/https://some_url');

0reactions
smitpatelxcommented, Mar 13, 2019

I cant change 'Access-Control-Allow-Origin': '*' as you suggested because I am using apis like github oauth. I am not building an API I am using it

Read more comments on GitHub >

github_iconTop Results From Across the Web

how to bypass Access-Control-Allow-Origin? - Stack Overflow
there is no way to baypass it. but you can put a file on your backend that performs the request. So you call...
Read more >
3 Ways to Fix the CORS Error — and How the Access-Control ...
Fix one: install the Allow-Control-Allow-Origin plugin. The quickest fix you can make is to install the moesif CORS extension .
Read more >
CORS - Misconfigurations & Bypass - HackTricks
You can ask a web-application to make a request for you and send back the response. This will bypass the Access-Control-Allow-Origin but notice...
Read more >
Access-Control-Allow-Origin - HTTP - MDN Web Docs - Mozilla
The Access-Control-Allow-Origin response header indicates whether the response can be shared with requesting code from the given origin.
Read more >
How to bypass 'Access-Control-Allow-Origin' error with ...
If you're a curious developer in some point of your life you may already faced (or you will face) the cross-domain/same-origin policy.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found