Coder Social home page Coder Social logo

briancartercst / add-cors-to-couchdb Goto Github PK

View Code? Open in Web Editor NEW

This project forked from pouchdb/add-cors-to-couchdb

0.0 2.0 0.0 23 KB

CLI to add a good default CORS configuration to CouchDB

License: Apache License 2.0

JavaScript 83.99% Shell 16.01%

add-cors-to-couchdb's Introduction

Add CORS to CouchDB Build Status

Greenkeeper badge

Summary

CouchDB doesn't come with CORS enabled by default. This is a problem for libraries like PouchDB, 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 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:

HOST=http://adminname:password@localhost:5984 # or whatever you got

curl -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 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:

curl -X GET $HOST/_membership

to see the list of available nodes, then do e.g.:

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"'

add-cors-to-couchdb's People

Contributors

calvinmetcalf avatar dandamian avatar danhawkes avatar greenkeeper[bot] avatar nolanlawson avatar sajinshrestha avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.