How to enable CORS in go-ipfs Dockerfile

I’m trying to enable CORS for go-ipfs Docker file.

Here is what I have tried.

I added some config commands to enable CORS before we start the daemon:

RUN ipfs init \
    && 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"]'

Here is the complete (updated for CORS) Dockerfile.

Somehow the config is not CORS enabled in the final image. What am I doing wrong here?

cc @hector @stebalien

Thanks :slight_smile:

Any chance that you want to enable CORS for the Gateway but you are doing it for the API?

I’m trying to enable CORS for the APIs (on port 5001).

works for me. How are you testing, or why do you say it does not work?