Skip to content

Instantly share code, notes, and snippets.

@max-mapper
Created March 26, 2011 18:56
Show Gist options
  • Save max-mapper/888539 to your computer and use it in GitHub Desktop.
Save max-mapper/888539 to your computer and use it in GitHub Desktop.
couchdb cors _show function, put in the shows folder
function(head, req){
return {
"headers": {
"Access-Control-Allow-Origin": "*"
}
}
}
[
{
"from": "",
"to": "_show/cors",
"method": "OPTIONS"
}
]
@jhs
Copy link

jhs commented May 14, 2011

My new idea is you put /db/_security

{ "readers": ["blah"]
, "admins": ["blah"]
, "cors": { "origins": [ "http://some.foreign.origin.com", "http://somecouch.iriscouch.com:5984" ]
             }
}

And couch will support an OPTIONS query for any resource in that database, returning the headers it needs based on the client Origin

your validate_doc_update() can also decide about cross-origin updates, based on req.headers.Origin vs. sec.cors.origins

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment