incubator-couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Benoit Chesneau <bchesn...@gmail.com>
Subject Re: _rewrite handler
Date Sun, 06 Dec 2009 01:10:07 GMT
On Sun, Dec 6, 2009 at 12:27 AM, Roger Binns <rogerb@rogerbinns.com> wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> Benoit Chesneau wrote:
>> ? there is no prescribed behaviour
>
> With your current proposal behaviour is entirely determined by a Javascript
> function.  What I am proposing is that Javascript function also be given a
> doc as input to do with as it pleases.  There is no requirement for the doc
> to exist or the Javascript to pay any attention to it.

Well rewrite need to be fast. I don't like the idea of loading another
doc. However since ddoc is already loaded  it could be used in. We
just spoke with jchris about such possibily. I think that it will do
the trick.


>
>> main point of _rewrite handler is to rewrite urls in a couchdb node or
>> even cluster not on different subnets.
>
> You missed my point.  As an example a rewrite to a different show on the
> same server:
>
> function (req) {
>  if (req.path ... matches ... "show/details")
>    {
>       if( isinternal(req) )
>           return "... show/details-internal";
>       return ".... show/details-public";
>    }
> }
>
> Now the isinternal function needs to look at the IP address and would
> typically have a table of internal addresses.  With the current scheme that
> table would have to be built into the Javascript.

I don't see to have it in js is a problem. For the function needed to
test the ip I think we could need to add the ip in headers of request
object.
However I would stronly recommend to not rely on such function if you
need security. It's better to use a proxy and pass right auth headers.


>
>> system to rewrite urls. Sometimes you want to rewrite depending on
>> http verb, other depending on auth or simply on path and there are
>> different need for rewriting on patch too.  The current design allow
>> you to define your own way to do this. You could always make a
>> template that allows you to create your own set of rules.
>
> With your current proposal, code has to look like this:
>
> function (req) {
>   var data={ ... a bunch of data ... };
>
>   if/return/etc looking at the req and data
> }
>
> What I am asking for is the ability to have it like this:
>
> function (req, doc) {
>   if/return/etc looking at the req and data in doc
> }
>
> With your current proposal, changing the data used by the function requires
> regenerating Javascript code.  If the data can (optionally) live in a
> document then no code generation is required nor is rewriting the design doc.
>
> I would expect developers to come up with some useful rewriters.  For
> example maybe one that switches between production and development mode.  Or
> maybe some sort of aliasing as you suggested.  It would be nice to be able
> to control their behaviour by editing the contents of a regular doc rather
> than having to edit Javascript code and regenerating design docs.
>

You don't need to regerenate code you can use couchapp macro or any
templating system in current solution. However if you have access to
ddoc in function, you won't have to do this even.

- benoît

Mime
View raw message