You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@couchdb.apache.org by Ryan Ramage <ry...@gmail.com> on 2011/04/26 21:48:16 UTC

Simple rewrite rule help

Hello all,

Can I define rule(s) that looks like this?

http://hostname.com/db1  ->    /db1/_design/app/_rewrite
http://hostname.com/db2  ->    /db2/_design/app/_rewrite
http://hostname.com/db3  ->    /db3/_design/app/_rewrite

... and so on

or, if that messes up accessing the docs/endpoints, maybe

http://hostname.com/_db1  ->    /db1/_design/app/_rewrite
http://hostname.com/_db2  ->    /db2/_design/app/_rewrite
http://hostname.com/_db3  ->    /db3/_design/app/_rewrite


Notice, the hostname is the same, so I can't use a vhost rule. Also, I
would like to have it on a design doc (so it replicates), or only have
to perform the config once per server.


Is that possible? ( using couch 1.1 or greater if that helps)

Re: Simple rewrite rule help

Posted by Benoit Chesneau <bc...@gmail.com>.
On Tue, Apr 26, 2011 at 10:00 PM, Ryan Ramage <ry...@gmail.com> wrote:
> Great, and can it be done with one generic rule, with a variable?
>
> something like:
> hostname.com:/${db} = ${db}/_design/app/_rewrite
>

Nope you can't. What you can do is:

:db.hostname.com = :db/_design/app/_rewrite should work.


>
>
> On Tue, Apr 26, 2011 at 1:52 PM, Benoit Chesneau <bc...@gmail.com> wrote:
>> On Tue, Apr 26, 2011 at 9:48 PM, Ryan Ramage <ry...@gmail.com> wrote:
>>> Hello all,
>>>
>>> Can I define rule(s) that looks like this?
>>>
>>> http://hostname.com/db1  ->    /db1/_design/app/_rewrite
>>> http://hostname.com/db2  ->    /db2/_design/app/_rewrite
>>> http://hostname.com/db3  ->    /db3/_design/app/_rewrite
>>>
>>> ... and so on
>>>
>>> or, if that messes up accessing the docs/endpoints, maybe
>>>
>>> http://hostname.com/_db1  ->    /db1/_design/app/_rewrite
>>> http://hostname.com/_db2  ->    /db2/_design/app/_rewrite
>>> http://hostname.com/_db3  ->    /db3/_design/app/_rewrite
>>>
>>>
>>> Notice, the hostname is the same, so I can't use a vhost rule. Also, I
>>> would like to have it on a design doc (so it replicates), or only have
>>> to perform the config once per server.
>>>
>>>
>>> Is that possible? ( using couch 1.1 or greater if that helps)
>>>
>>
>> afaik you can use vhosts rules with a path :
>>
>> hostname.com:/app1 = db1/_design/app/_rewrite
>> hostname.com:/app2 = db2/_design/app/_rewrite
>>
>> On the other hand I doubt you can use the _ here, but you can test.
>>
>> - benoît
>>
>> - benoit
>>
>

Re: Simple rewrite rule help

Posted by "Johannes J. Schmidt" <sc...@netzmerk.com>.
Am Mittwoch, den 27.04.2011, 11:01 +0200 schrieb Benoit Chesneau:
> No real reason to not support it actualy, it just haven't been thought
> this way, Maybe you could open a ticket about it?
> 
> On the other hand I  think though that this should be handled
> differently. Still working on it but implementation is coming soon.
I am full of expectation.

In the meantime, I will open a ticket for variable substitution on
paths.

g jo

Re: Simple rewrite rule help

Posted by Benoit Chesneau <bc...@gmail.com>.
On Wed, Apr 27, 2011 at 9:09 AM, Johannes J. Schmidt
<sc...@netzmerk.com> wrote:

>
> Just to make it clear: it seems like
>  ":appname.:dbname.example.com" => "/:dbname/_design/:appname/_rewrite/"
> should work but you mention that variable substitution in paths is not
> supported, so
>  ":appname.example.com/:dbname" => "/:dbname/_design/:appname/_rewrite/"
> would not work?
> And when, why is this not supported? Is it according to 1103?
>

No real reason to not support it actualy, it just haven't been thought
this way, Maybe you could open a ticket about it?

On the other hand I  think though that this should be handled
differently. Still working on it but implementation is coming soon.

- benoit

Re: Simple rewrite rule help

Posted by "Johannes J. Schmidt" <sc...@netzmerk.com>.
Am Mittwoch, den 27.04.2011, 08:47 +0200 schrieb Benoit Chesneau:
> On Wed, Apr 27, 2011 at 8:19 AM, Johannes J. Schmidt
> <sc...@netzmerk.com> wrote:
> 
> > Could you point me to some documentation about that feature?
> >
> I should update the wiki. In the mean time, you can have a look on the tests:
> 
> https://github.com/benoitc/couchdb/blob/master/test/etap/160-vhosts.t
Thanks.

Just to make it clear: it seems like
 ":appname.:dbname.example.com" => "/:dbname/_design/:appname/_rewrite/"
should work but you mention that variable substitution in paths is not
supported, so
 ":appname.example.com/:dbname" => "/:dbname/_design/:appname/_rewrite/"
would not work?
And when, why is this not supported? Is it according to 1103?

g jo

Re: Simple rewrite rule help

Posted by Benoit Chesneau <bc...@gmail.com>.
On Wed, Apr 27, 2011 at 8:19 AM, Johannes J. Schmidt
<sc...@netzmerk.com> wrote:

> Could you point me to some documentation about that feature?
>
I should update the wiki. In the mean time, you can have a look on the tests:

https://github.com/benoitc/couchdb/blob/master/test/etap/160-vhosts.t

- benoît

Re: Simple rewrite rule help

Posted by "Johannes J. Schmidt" <sc...@netzmerk.com>.
Am Mittwoch, den 27.04.2011, 07:46 +0200 schrieb Benoit Chesneau:
> On Tuesday, April 26, 2011, Johannes J. Schmidt <sc...@netzmerk.com> wrote:
> > Am Dienstag, den 26.04.2011, 14:00 -0600 schrieb Ryan Ramage:
> >> Great, and can it be done with one generic rule, with a variable?
> >>
> >> something like:
> >> hostname.com:/${db} = ${db}/_design/app/_rewrite
> >
> > From my knowing there is no variable substitution inside vhosts
> > definitions.
> >
> > I am using kind of a route document with the rule
> >  {
> >    "from": "/:db",
> >    "to": "../../../:db/_design/app/_rewrite"
> >  }
> > and a vhost definition like
> >   hostname.com = master/_design/router/_rewrite
> > to achieve that.
> >
> > g jo
> >
> >
> 
> There is but not in paths :)
> 
> benoit
Could you point me to some documentation about that feature?

g jo

Re: Simple rewrite rule help

Posted by Benoit Chesneau <bc...@gmail.com>.
On Tuesday, April 26, 2011, Johannes J. Schmidt <sc...@netzmerk.com> wrote:
> Am Dienstag, den 26.04.2011, 14:00 -0600 schrieb Ryan Ramage:
>> Great, and can it be done with one generic rule, with a variable?
>>
>> something like:
>> hostname.com:/${db} = ${db}/_design/app/_rewrite
>
> From my knowing there is no variable substitution inside vhosts
> definitions.
>
> I am using kind of a route document with the rule
>  {
>    "from": "/:db",
>    "to": "../../../:db/_design/app/_rewrite"
>  }
> and a vhost definition like
>   hostname.com = master/_design/router/_rewrite
> to achieve that.
>
> g jo
>
>

There is but not in paths :)

benoit

Re: Simple rewrite rule help

Posted by "Johannes J. Schmidt" <sc...@netzmerk.com>.
I forgot to note that you must set
  secure_rewrites = false
(under section httpd) in order to allow cross-db rewriting.

g jo
Am Dienstag, den 26.04.2011, 14:26 -0600 schrieb Ryan Ramage:
> I think I just noticed in JIRA there is discussion to jail (Or
> prevent) those kind of rewrites.
> 
> https://issues.apache.org/jira/browse/COUCHDB-759
> 
> 
> 
> On Tue, Apr 26, 2011 at 2:23 PM, Johannes J. Schmidt
> <sc...@netzmerk.com> wrote:
> > Am Dienstag, den 26.04.2011, 14:00 -0600 schrieb Ryan Ramage:
> >> Great, and can it be done with one generic rule, with a variable?
> >>
> >> something like:
> >> hostname.com:/${db} = ${db}/_design/app/_rewrite
> >
> > From my knowing there is no variable substitution inside vhosts
> > definitions.
> >
> > I am using kind of a route document with the rule
> >  {
> >   "from": "/:db",
> >   "to": "../../../:db/_design/app/_rewrite"
> >  }
> > and a vhost definition like
> >  hostname.com = master/_design/router/_rewrite
> > to achieve that.
> >
> > g jo
> >
> >

-- 
Netzmerk GbR
Johannes J. Schmidt

http://netzmerk.com
01525 378 65 21

Am Vierstückenpfuhl 3a
14167 Berlin

Re: Simple rewrite rule help

Posted by Ryan Ramage <ry...@gmail.com>.
I think I just noticed in JIRA there is discussion to jail (Or
prevent) those kind of rewrites.

https://issues.apache.org/jira/browse/COUCHDB-759



On Tue, Apr 26, 2011 at 2:23 PM, Johannes J. Schmidt
<sc...@netzmerk.com> wrote:
> Am Dienstag, den 26.04.2011, 14:00 -0600 schrieb Ryan Ramage:
>> Great, and can it be done with one generic rule, with a variable?
>>
>> something like:
>> hostname.com:/${db} = ${db}/_design/app/_rewrite
>
> From my knowing there is no variable substitution inside vhosts
> definitions.
>
> I am using kind of a route document with the rule
>  {
>   "from": "/:db",
>   "to": "../../../:db/_design/app/_rewrite"
>  }
> and a vhost definition like
>  hostname.com = master/_design/router/_rewrite
> to achieve that.
>
> g jo
>
>

Re: Simple rewrite rule help

Posted by "Johannes J. Schmidt" <sc...@netzmerk.com>.
Am Dienstag, den 26.04.2011, 14:00 -0600 schrieb Ryan Ramage:
> Great, and can it be done with one generic rule, with a variable?
> 
> something like:
> hostname.com:/${db} = ${db}/_design/app/_rewrite

From my knowing there is no variable substitution inside vhosts
definitions.

I am using kind of a route document with the rule
 {
   "from": "/:db",
   "to": "../../../:db/_design/app/_rewrite"
 }
and a vhost definition like
  hostname.com = master/_design/router/_rewrite
to achieve that.

g jo


Re: Simple rewrite rule help

Posted by Ryan Ramage <ry...@gmail.com>.
Great, and can it be done with one generic rule, with a variable?

something like:
hostname.com:/${db} = ${db}/_design/app/_rewrite



On Tue, Apr 26, 2011 at 1:52 PM, Benoit Chesneau <bc...@gmail.com> wrote:
> On Tue, Apr 26, 2011 at 9:48 PM, Ryan Ramage <ry...@gmail.com> wrote:
>> Hello all,
>>
>> Can I define rule(s) that looks like this?
>>
>> http://hostname.com/db1  ->    /db1/_design/app/_rewrite
>> http://hostname.com/db2  ->    /db2/_design/app/_rewrite
>> http://hostname.com/db3  ->    /db3/_design/app/_rewrite
>>
>> ... and so on
>>
>> or, if that messes up accessing the docs/endpoints, maybe
>>
>> http://hostname.com/_db1  ->    /db1/_design/app/_rewrite
>> http://hostname.com/_db2  ->    /db2/_design/app/_rewrite
>> http://hostname.com/_db3  ->    /db3/_design/app/_rewrite
>>
>>
>> Notice, the hostname is the same, so I can't use a vhost rule. Also, I
>> would like to have it on a design doc (so it replicates), or only have
>> to perform the config once per server.
>>
>>
>> Is that possible? ( using couch 1.1 or greater if that helps)
>>
>
> afaik you can use vhosts rules with a path :
>
> hostname.com:/app1 = db1/_design/app/_rewrite
> hostname.com:/app2 = db2/_design/app/_rewrite
>
> On the other hand I doubt you can use the _ here, but you can test.
>
> - benoît
>
> - benoit
>

Re: Simple rewrite rule help

Posted by Benoit Chesneau <bc...@gmail.com>.
On Tue, Apr 26, 2011 at 9:48 PM, Ryan Ramage <ry...@gmail.com> wrote:
> Hello all,
>
> Can I define rule(s) that looks like this?
>
> http://hostname.com/db1  ->    /db1/_design/app/_rewrite
> http://hostname.com/db2  ->    /db2/_design/app/_rewrite
> http://hostname.com/db3  ->    /db3/_design/app/_rewrite
>
> ... and so on
>
> or, if that messes up accessing the docs/endpoints, maybe
>
> http://hostname.com/_db1  ->    /db1/_design/app/_rewrite
> http://hostname.com/_db2  ->    /db2/_design/app/_rewrite
> http://hostname.com/_db3  ->    /db3/_design/app/_rewrite
>
>
> Notice, the hostname is the same, so I can't use a vhost rule. Also, I
> would like to have it on a design doc (so it replicates), or only have
> to perform the config once per server.
>
>
> Is that possible? ( using couch 1.1 or greater if that helps)
>

afaik you can use vhosts rules with a path :

hostname.com:/app1 = db1/_design/app/_rewrite
hostname.com:/app2 = db2/_design/app/_rewrite

On the other hand I doubt you can use the _ here, but you can test.

- benoît

- benoit