incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From 7zark7 <7za...@gmail.com>
Subject Re: Writing custom rewrite handler?
Date Tue, 15 Jun 2010 14:41:20 GMT
That's awesome, thanks Benoit.


On 6/15/10 7:18 AM, Benoit Chesneau wrote:
> The diff :
>
> http://github.com/benoitc/couchdb/commit/32783433b9f0030a9e6ac2f995d6cd7098794921
>
> On Tue, Jun 15, 2010 at 4:16 PM, Benoit Chesneau<bchesneau@gmail.com>  wrote:
>> On Tue, Jun 15, 2010 at 7:31 AM, 7zark7<7zark7@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
>>


Mime
View raw message