Hi,
Folloging suggestion of @jchris I revisited my rewrite handler. This
time instead of using a javascript function to handle rewriting it
uses pattern matching in Erlang to do it. The rewriting root is the
the design doc :
/yourdb/_design/ddocname/_rewrite/....
ddocname should contain a "rewrites" member which a list of rewriting
rules. If not it will return a 404.
ex :
{
....
"rewrite": [
{
"from": "",
"to": "index.html",
"method": "GET",
"query": {}
}
]
}
Urls are relatives to the db if they start by / or to the current path.
Rewriting can use variables. Variables in path are prefixed by ":".
For example the following rule:
{ "from": "show/:id", "to": "_show/mydoc/:id" }
will rewrite
"/mydb/_design/test/_rewrite/show/someid" to
"/mydb/_design/test/_rewrite/_show/someid".
or { "from": "view/:type", "to": "_list/types/by_types", query: {
"key": "type" }
will rewrite :
"/mydb/_design/test/_rewrite/view/sometype" to
"/mydb/_design/test/_rewrite/_list/types/by_types?key=sometype".
So paths and query args can be rewrittend dynamically. The code is
currently in my github repo :
http://github.com/benoitc/couchdb/commits/rewrite2
(couch_httpd_rewrite.erl) .
There is also some unitests :
http://github.com/benoitc/couchdb/blob/rewrite2/share/www/script/test/rewrite.js
Let me know what do you think about it.
- benoƮt