4

I have setup a cloudant local database using docker image.

When I try to send in a cloudant query using a JavaScript application hosted on localhost:8000 it gives me an CORS error.

How do I enable CORS on Cloudant local? I have tried the following

  1. PUT request as described in https://docs.cloudant.com/cors.html#setting-the-cors-configuration
  2. Checked the dashboard but the local instance does not have the "Account" tab available. Cloudant Local dashboard
anirus
  • 1,597
  • 2
  • 18
  • 24

3 Answers3

1

Same answer as @anirus, but there's a very kludgy way around it. If you have named the container cloudant-developer as in the current instructions at https://hub.docker.com/r/ibmcom/cloudant-developer/:

  • Save the stock default.ini file locally:

    docker exec cloudant-developer cat /opt/cloudant/etc/default.ini > default.ini

  • Modify it so that enable_cors = true instead of false

  • In the [cors] section, add a line like origins = http://localhost:3000. It should also take a comma delimited list, but then you're probably only working on one app at a time.

  • Volume mount the modified default.ini over the original whenever you run the container by adding -v `pwd`/default.ini:/opt/cloudant/etc/default.ini to docker's list of command line arguments:

    docker run --privileged --detach --volume cloudant:/srv -v `pwd`/default.ini:/opt/cloudant/etc/default.ini --name cloudant-developer --publish 8080:80 --hostname cloudant.dev ibmcom/cloudant-developer

nitind
  • 19,089
  • 4
  • 34
  • 43
1

This can be done using a custom Dockerfile which edits the Cloudant settings file before the database is started. I used this -

FROM ibmcom/cloudant-developer:latest

RUN \
  sed -i 's/enable_cors = false/enable_cors = true/g' /opt/cloudant/etc/default.ini && \
  sed -i 's/\[cors\]/\[cors\]\norigins=*/g' /opt/cloudant/etc/default.ini && \
  sed -i 's/credentials = false/credentials = true/g' /opt/cloudant/etc/default.ini

It will enable cors with origins=* and also accept credentials from CORS connections.

You can put that in a Dockerfile, then docker build and docker run it.

AvnerSo
  • 1,609
  • 1
  • 16
  • 23
0

All my investigation so far indicates that this is not supported on local Cloudant.

anirus
  • 1,597
  • 2
  • 18
  • 24