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