On Tue, Jun 15, 2010 at 7:31 AM, 7zark7 <7za...@gmail.com> wrote: > I like the simplicity of the supplied rewrite handler, but I'm finding that > does not meet my needs. > > I need to do arbitrary rewrites that involve string concatination, URL > encoding, and other such logic., and would like to avoid an external process > such as nginx, or Apache. > > Being able to write a rewrite as a javascript function inside a design doc > seems like a perfect solution, but unsure how difficult this would be. I am > new to Erlang. > > Could anyone offer any tips to get me started? > > Would this require a custom fork/build of Couch, or could this handler be > added via configuration? > > Thank you >
The rewriter you may want is here : http://github.com/benoitc/couchdb/tree/rewrite ex : http://github.com/benoitc/couchdb/blob/rewrite/share/www/script/test/rewrite.js relevant part : function (req) { path = "/" + req.path.join('/'); if (path == "/forbidden") { throw {forbidden: "path forbidden"}; } if (path == "/unauthorized") { throw {unauthorized: "path not authorized"}; } if (path == "/notfound") { throw {not_found: "path not found"}; } if (path == "/foo") { return "foo.txt" } var matches = path.match(/^\/hello\/(\w.+)$/); if (matches[1]) { if (req.verb == "DELETE") { throw {forbidden: "delete is forbidden"}; } return "_update/hello/" + matches[1]; } the problem with a rewriter using js, is that you will kill yourserver under load since it will create one process / request. That the reason I wrote the current rewriter in full erlang. To use a js rewriter we need to use something like emonk or erlang_js so we don't open an os process. - benoit