Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changed vhost and rewrite in CouchDB and can't access the internal API

Tags:

couchdb

I wanted to map my custom domain to a design document _rewrite.

// Configuration

vhosts     www.myapp.com    /myapp/_design/user/_rewrite

// Rewrites

[{
  "from": "",
  "to": "static/browser/index.html"
}, {
  "from": "*",
  "to": "*"
}]

The first route works fine. I can access the index.html with www.myapp.com. However, now I can't access www.myapp.com/_utils. It says _all_dbs can't be found in the browser console. All other APIs stop working as well.

I guess this is because that path is now converted to /myapp/_design/user/_utils.

How can I fix this?

like image 491
ajsie Avatar asked Jul 10 '11 11:07

ajsie


1 Answers

_utils and other "special" paths do not cooperate with vhosts very well. Last I checked (version 1.0.2 I think), _utils will display the Futon UI however its AJAX calls to _all_dbs and others will fail and it is a total mess.

I suggest a strict separation between your app and your internal management. Use the vhost for the application, but always avoid vhosts when accessing Futon or other tools.

There are a few tricks to avoid your vhost.

  • Use the server IP address instead of the domain name: http://1.2.3.4:5984
  • Use a different port if possible: http://www.myapp.com:5984 or https://www.myapp.com:6984
  • Add an alternative DNS entry pointing to the same couch and use that: http://futon.myapp.com
  • Add a dot at the end of your domain. http://www.myapp.com./ — This is very sneaky (or clever). That is a valid DNS name however CouchDB treats it differently from www.myapp.com therefore you will not trigger the vhost.
like image 132
JasonSmith Avatar answered Sep 27 '22 20:09

JasonSmith