MunifTanjim / node-bitbucket

Bitbucket API client for Browser and Node.js
https://bitbucketjs.netlify.app
MIT License
106 stars 28 forks source link

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

Open PetrShchukin opened 4 years ago

PetrShchukin commented 4 years ago

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",

MunifTanjim commented 4 years ago

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.

PetrShchukin commented 4 years ago

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 =/

MunifTanjim commented 4 years ago

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

PetrShchukin commented 4 years ago

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}"
MunifTanjim commented 4 years ago

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

MunifTanjim commented 4 years ago

image

Now it's working again!

PetrShchukin commented 4 years ago

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