If you have a couchapp and want to have nice URLS, go read this blogpost. If you still don’t get it, here is how to do it. It doesn’t work with my outliner app, because it is so entangled with old couchapp and jquery.couch.js versions and I’m not up to upgrade hell right now. But I’ll write it down for my next project and for you, yay.
Let’s say you have an app running at http://account.couchone.com/mydb/_design/doingnotes/index.html and want to add the additional URL http://account.couchone.com/index.html. First you have to set up a virtual host. (Want to know why? Go back read the blogpost). If you are using a hosted CouchDB instance and don’t have access to the local.ini file, you can also do this remotely:
curl -X PUT http://username:password@account.couchone.com/_config/vhosts/account.couchone.com -d '"/mydb/_design/doingnotes/_rewrite"'Check at the bottom of http://account.couchone.com/_utils/config.html if there is a key value pair “account.couchone.com” => “/mydb/_design/doingnotes/_rewrite”.
Now it won’t work yet, because you still have to add the rewrite(s) to your design document. Do this by adding a file “rewrites.json” in your project folder. I has to contain an array of json objects with a “from” and a “to” attribute each. They work down in the path starting with the design document (the “doingnotes” in the URL). You can use wildcards. “from” specifies where it should map from, “to” which file it should map to. This is how rewrites.json looks for my application:
[{
"from": "",
"to": "index.html"
},
{
"from": "vendor/*",
"to": "vendor/*"
},
{
"from": "app/*",
"to": "app/*"
},
{
"from": "config/*",
"to": "config/*"
},
{
"from": "_view/*",
"to": "_view/*"
}]If you just put the first from/to pair in, you can already call the application, but it won’t work because the code in the design document needs access to all the folders that are stored in the application’s root level (that is not in the “_attachments” folder). The wildcards map everything down from that path. If you have code in other locations as well, you have to add rewrites for those folders too. That’s it.
Trackbacks
Use the following link to trackback from your own site:
http://lenaherrmann.net/trackbacks?article_id=18
about 1 hour later:
Good explanation of the rewriting, you should consider contributing this to the book :-)
27 days later:
Thanks, nice writeup. Unfortunately it didn’t work for me, yet.
How can I know if the PUT request was successful or not? When I curl it, I get no respoOn my couchone account, ‘Empty reply from server,’ which doesn’t seem very relaxy. And no new vhost field appeared in _utils/config.html afterwards.
It mentions the following at the top of _utils/config.html, however:
“Note: Some configuration options may require restarting the server to take effect after modification.”
Is it even possible to restart the server on couchone? Any advice?
about 1 month later:
Hi Murph,
when you visit utils/config.html and scroll right to the bottom, if the request has been successful you should see an entry there with section: vhosts, option: account.couchone.com, value: /mydb/design/doingnotes/_rewrite. If curl doesn’t work for you, you can also create that entry by clicking on “Add a new section”.
I think it’s not possible to restart a hosted couchone instance, but if you email hello@couchone.com they can tell you for sure.