ruimarinho / bitcoin-core

A modern Bitcoin Core REST and RPC client.
483 stars 188 forks source link

Preflight request error (CORS) #39

Closed blucet closed 7 years ago

blucet commented 7 years ago

Hello,

I'm running a Bitcoin node with bitcoind and the following configuration:

rpcuser=bitcoinrpc
rpcpassword=<pass>
server=1

When trying to connect with the following configuration and testing it with getInfo :

const client = new Client({
  host: 'localhost',
  username: 'bitcoinrpc',
  password: '<pass>'
})

client.getInfo().then((help) => console.log(help))

I get the following error :

Failed to load http://localhost:8332/: Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://localhost:8080' is therefore not allowed access. The response had HTTP status code 501. If an opaque response serves your needs, set the request's mode to 'no-cors' to fetch the resource with CORS disabled.

Is it possible to resolve that error without using something like "cors-anywhere"?

Thank you very much.

ruimarinho commented 7 years ago

Are you running this on a browser context? I'm asking because CORS doesn't apply to the node context, so I don't see how's that possible.

blucet commented 7 years ago

Yes I'm running this in the browser with Webpack. I ended up using corsproxy to make it work as a temporary solution, but the right solution is of course not related to this library. Enjoying bitcoin-core so far, thanks!

ruimarinho commented 7 years ago

That's strange, but I'm sure you've got the right reasons to do it :) you can try using the domain lvh.me as that one points to 127.0.0.1 as well (bypassing some browser's limitations on using CORS with localhost).

ruimarinho commented 7 years ago

Oh, and thanks for the comment of course!