Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/pouchdb/add-cors-to-couchdb
CLI to add a good default CORS configuration to CouchDB
https://github.com/pouchdb/add-cors-to-couchdb
Last synced: 4 days ago
JSON representation
CLI to add a good default CORS configuration to CouchDB
- Host: GitHub
- URL: https://github.com/pouchdb/add-cors-to-couchdb
- Owner: pouchdb
- License: apache-2.0
- Created: 2014-08-22T11:22:34.000Z (over 10 years ago)
- Default Branch: master
- Last Pushed: 2020-03-16T07:39:21.000Z (almost 5 years ago)
- Last Synced: 2025-02-07T20:08:41.025Z (14 days ago)
- Language: JavaScript
- Homepage:
- Size: 35.2 KB
- Stars: 133
- Watchers: 16
- Forks: 17
- Open Issues: 7
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
- awesome-starred - pouchdb/add-cors-to-couchdb - CLI to add a good default CORS configuration to CouchDB (others)
README
Add CORS to CouchDB [](https://travis-ci.org/pouchdb/add-cors-to-couchdb)
====[](https://greenkeeper.io/)
#### Summary
CouchDB doesn't come with [CORS](https://en.wikipedia.org/wiki/Cross-Origin_Resource_Sharing) enabled by default. This is a problem for libraries like [PouchDB](http://pouchdb.com), which depend on being able to access CouchDB no matter what URL it's being served from. This script fixes that.
#### Usage
You need to have [Node.js and NPM](https://nodejs.org) installed. Then do:
```
npm install -g add-cors-to-couchdb
add-cors-to-couchdb
```Or if it is a remote database:
```
add-cors-to-couchdb http://me.iriscouch.com -u myusername -p mypassword
```##### Ubuntu - special instructions
On Ubuntu the default Node.js library is called `nodejs` instead of `node` due to a naming conflict. To run on Ubuntu, you'll need to do:
```
sudo apt-get install nodejs-legacy
```#### What it does
This script will simply add some generic CORS configuration to your CouchDB. You could also do it yourself trivially using `curl`:
```bash
HOST=http://adminname:password@localhost:5984 # or whatever you gotcurl -X PUT $HOST/_config/httpd/enable_cors -d '"true"'
curl -X PUT $HOST/_config/cors/origins -d '"*"'
curl -X PUT $HOST/_config/cors/credentials -d '"true"'
curl -X PUT $HOST/_config/cors/methods -d '"GET, PUT, POST, HEAD, DELETE"'
curl -X PUT $HOST/_config/cors/headers -d '"accept, authorization, content-type, origin, referer, x-csrf-token"'
```You can always change the configuration later by simply going to [http://localhost:5984/_utils/config.html](http://localhost:5984/_utils/config.html) and updating the values. However, these default options are good for getting up and running.
#### CouchDB 2.0+ instructions
This modules automatically detects CouchDB 2.0 and should do the right thing. But in case
you need to configure CORS on a per-node basis, do:```bash
curl -X GET $HOST/_membership
```to see the list of available nodes, then do e.g.:
```bash
curl -X PUT $HOST/_node/[email protected]/_config/httpd/enable_cors -d '"true"'
curl -X PUT $HOST/_node/[email protected]/_config/cors/origins -d '"*"'
curl -X PUT $HOST/_node/[email protected]/_config/cors/credentials -d '"true"'
curl -X PUT $HOST/_node/[email protected]/_config/cors/methods -d '"GET, PUT, POST, HEAD, DELETE"'
curl -X PUT $HOST/_node/[email protected]/_config/cors/headers -d '"accept, authorization, content-type, origin, referer, x-csrf-token"'
```