I'm trying to spin up a very simple blog engine in CouchDB. Each post has a
"path" property like "2010/11/building_ppc_couchdb" that I'd like to use via a
rewrite rule as follows:
{
"from": "/blog/*",
"to": "_list/posts/by_path",
"query": {
"include_docs": "true",
"key": "*"
}
}
However, the asterisk in the rewrite rule seems to only capture the first path
component in the logs I see:
/dev/_design/glob/_rewrite/blog/2010/11/building_ppc_couchdb ...get
rewritten to:
/dev/_design/glob/_list/posts/by_path?key=%222010%22&include_docs=true
So I thought maybe I'll just set up four or five rules like:
{
"from": "/blog/:path1/:path2/:path3/",
"to": "_list/posts/by_path",
"query": {
"include_docs": "true",
"key": ":path1/:path2/:path3"
}
}
...to handle anywhere from one to several path components. But in that case the
variables in "key" don't get rewritten:
/dev/_design/glob/_list/posts/by_path?key=%22%3Apath1%2F%3Apath2%2F%3Apath3%22&include_docs=true&path1=2010&path2=11&path3=building_ppc_couchdb
The rewriter logic seems frustratingly fickle; are both of the above examples
behaving as intended? The wiki documentation is pretty clear as far as matching
goes, but fuzzy as far as how the subsequent templating into the "to" and
"query" values is supposed to work.
The only way I've been able to figure out is to tweak my view function to
.split("/") the path before emitting it, and then set up a handful of rules
like:
{
"from": "/blog/:path1/",
"to": "_list/posts/by_path",
"query": {
"include_docs": "true",
"key": [":path1"]
}
}, {
"from": "/blog/:path1/:path2/",
"to": "_list/posts/by_path",
"query": {
"include_docs": "true",
"key": [":path1",":path2"]
}
}, {
"from": "/blog/:path1/:path2/:path3/",
"to": "_list/posts/by_path",
"query": {
"include_docs": "true",
"key": [":path1",":path2",":path3"]
}
}, {
"from": "/blog/:path1/:path2/:path3/:path4/",
"to": "_list/posts/by_path",
"query": {
"include_docs": "true",
"key": [":path1",":path2",":path3",":path4"]
}
}
This works, but is there a better way to accomplish this general idea?
thanks,
-natevw