incubator-couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Jason Davies <ja...@jasondavies.com>
Subject Re: Rewriting URLs
Date Sat, 04 Jul 2009 21:51:56 GMT
On 4 Jul 2009, at 22:34, Jason Davies wrote:

> I've mostly completed work on a patch for a _rewrite handler.  This  
> was one of the main missing pieces for me when trying to provide  
> pretty/clean URLs when using CouchDB to deploy pure CouchApps behind  
> a reverse proxy (Nginx).  My approach up until now has been to use  
> Nginx's mod_rewrite to rewrite URLs using regular expressions.   
> However, this is not workable for those of us who want to replicate  
> CouchApps in a portable manner.
>
> The basic idea is you add a "rewrites": [...] member to your design  
> doc.  This will allow rewriting of any URLs with the prefix mydb/ 
> _design/app/_rewrite.  The "rewrites" member is a list of rewrite  
> rules of the form {match: ["foo/bar/<var>"], rewrite:["_view/ 
> myview", {startkey: ["<var>"], endkey: ["<var>", {}]}]
>
> This is very similar to WebMachine's routing syntax, which would be  
> something like ["foo", "bar", var] for the match part.  Notice how  
> "<var>" is used to denote an atom.  Atoms in the target path and in  
> the target query parameters are replaced with any tokens they  
> matched in the source rule.  There is a special atom '*' that can be  
> used (as in WebMachine) to match any number of path elements  
> (normally atoms match a single path element).

[snip]

Just thought of a limitation in the current code in that it only  
generates strings in the target query parameters, which isn't useful  
if you want to have keys containing booleans or numbers.  I'm thinking  
of using something similar to Werkzeug's syntax (http://werkzeug.pocoo.org/documentation/dev/routing.html

) e.g. <number:var> or <bool:var>.  Alternatively I could have a  
modifier in the target atoms e.g. <safe:var> to indicate that the  
variable can be sent straight through without being JSON-encoded as a  
string.

--
Jason Davies

www.jasondavies.com


Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message