Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to do cross-origin requests on IPFS

So I want to put a website on ipfs, but it has some javascript which calls out to a server that is not the ipfs gateway, so I get cross origin errors. Any idea how to do this?

like image 331
syzygy Avatar asked Mar 10 '17 00:03

syzygy


1 Answers

You can set the Access-Control-Allow-Origin header and other headers using ipfs config:

ipfs config --json API.HTTPHeaders.Access-Control-Allow-Origin '["*"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Methods '["GET", "POST"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Headers '["Authorization"]'
ipfs config --json API.HTTPHeaders.Access-Control-Expose-Headers '["Location"]'
ipfs config --json API.HTTPHeaders.Access-Control-Allow-Credentials '["true"]'

The values above are just examples; set the real values to what your client code actually needs.

https://docs.ipfs.io/reference/api/cli/#ipfs-daemon has the (minimal) existing docs on this.

like image 154
sideshowbarker Avatar answered Sep 28 '22 07:09

sideshowbarker