node-bitbucket icon indicating copy to clipboard operation
node-bitbucket copied to clipboard

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at

Open PetrShchukin opened this issue 5 years ago • 7 comments

Is there a working example? I'm tying

  const bitbucket = new Bitbucket();

  bitbucket.repositories
    .list({ workspace: "MunifTanjim" })
    .then(({ data }) => console.log(data.values))
    .catch((err) => console.error(err));

but having a cors error. "bitbucket": "^2.1.0",

PetrShchukin avatar May 17 '20 18:05 PetrShchukin

Are you using this from browser? Maybe Bitbucket doesn't allow cross-origin requests anymore 🤷‍♂️

I just ran your code here: https://npm.runkit.com/bitbucket and it worked alright.

MunifTanjim avatar May 17 '20 18:05 MunifTanjim

It works from npm.runkit.com... I've created react app, tried from there, but got a cors error. With an axios request and their rest api it works fine =/

PetrShchukin avatar May 17 '20 18:05 PetrShchukin

Can you show me a minimal project with this bug?

I can use it without any problem here: https://codesandbox.io/s/bitbucket-with-cra-c5rk2

MunifTanjim avatar May 17 '20 19:05 MunifTanjim

But your example doesn't work... I'm getting 500 error, probably the original error on codesandbox is hidden

"{"name":"HTTPError","headers":{},"request":{"method":"GET","url":"https://api.bitbucket.org/2.0/repositories/MunifTanjim","headers":{"accept":"application/json","user-agent":"bitbucket.js/2.1.0"},"request":{"validate":{"role":{"enum":["admin","contributor","member","owner"],"type":"string"},"workspace":{"required":true,"type":"string"}}}},"status":500}"

PetrShchukin avatar May 18 '20 09:05 PetrShchukin

Strange :thinking: I was working yesterday when I created that sandbox. Now it's not working anymore!

MunifTanjim avatar May 18 '20 12:05 MunifTanjim

image

Now it's working again!

MunifTanjim avatar May 18 '20 15:05 MunifTanjim

Still getting a 500 error on codesandbox and cors in a react app 🤷‍♂️. I've created a react app by using 'npx create-react-app myapp', then 'yarn add bitbucket', then simply add

  const bitbucket = new Bitbucket();
  React.useEffect(() => {
    bitbucket.repositories
      .list({ workspace: "MunifTanjim" })
      .then(({ data }) => console.log(data))
      .catch(err => {
        console.error(err);
      });
  }, [bitbucket.repositories]);

to App.js

PetrShchukin avatar May 18 '20 16:05 PetrShchukin