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?

The Dockerfile works, but CORS is not enabled when I start the container.

I’m trying to add some changes to the Dockerfile so that CORS is enabled by default when the container starts.

maybe with command ipfs config or change directly config file

You can set a cronjob to run the CORS commands on container startup. Though if you are reusing this container, and have volumes mounted you should only need to pass these into the container once.