Configuring Access-Control-Allow-Origin

Hi,

I’m playing with ipfs and js-ipfs-api but I’m having problems with configuring Access-Control-Allow-Origin header.
I’ve followed the instructions from official documentation and also from https://github.com/INFURA/tutorials/wiki/IPFS-and-CORS (I’ve set the * instead of some url)but when I try to use js api and read the file I get the following error:

Failed to load https://ipfs.infura.io:5001/api/v0/cat?arg=QmYzWWCvYhqU6d5VvRvVwgbpqM9J3HH8TMbns9UvFSSvBf&stream-channels=true: The ‘Access-Control-Allow-Origin’ header has a value ‘null’ that is not equal to the supplied origin. Origin ‘null’ is therefore not allowed access. Have the server send the header with a valid value, or, if an opaque response serves your needs, set the request’s mode to ‘no-cors’ to fetch the resource with CORS disabled.

Any help is really appreciated!

Is your gateway deployed at ipfs.infura.io? That seems to be the public gateways that Infura runs, maybe not the one you have running yourself?

Could you post an example of how you are using js-ipfs-api exactly?

Hey Victor, thanks for your response but I found what was the problem.
I am ashamed to say this, but the problem was the way I’ve opened my html file :frowning: .
Since I was not serving the file from server Access-Control-Allow-Origin headers value was “null”.
I’ve used surge.sh for quick test and it works like a charm.

1 Like