couchdb-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Johs Ensby <>
Subject Re: [PROPOSAL] Allow rewrites to be JS function
Date Sat, 17 Oct 2015 14:45:42 GMT
Thanks for your efforts, ermouth

I have been playing with it using the community AMI you put up adn it works just great.
It is a big step forward for couchapps since it is not possible to 
use username, or role from userCtx in rewrite rules
you can use the users IP address to firewall your system
you can redirect from GET to PUT
by going from a simple path, pick up username from userCtx, add timestamp and other context
info you have a lot to play with
doing so by pointing to a _update function expands the possibilities further
creating nested rules is really easy
using regExp offers another host of possibilities
since you can return a http code and body directly, you can skip creating pages for common
respons. A simple template function and the this.template[whatever] that is sitting in your
ddoc will do in most cases, especially having usrCtx available

What I did was to create a EC2 instannce, redirect traffic on port 80 directly to CouchDB
2, set up a few vhosts and their corresponding design documents.
I always set up a design document to the the API for my app or system of apps and it feels
akward to speak of a rewrite handler after this.

_rewrite concecptual upgrade #1
At least we now have a router management system.
It would be easy to implement your favourite router in the CouchDB _rewrite, making nice isomorphic

_rewrite concecptual upgrade #2
I woud call my first experiment an API server. Inside a ddoc, yes. 
The simplicity is a bit hard to grasp.
The power of this simplicity is even hard to grasp.

I hope there is someone that would pick up where ermouth left this and push it through testing
so it could be released with 2.0
It unlocks a lot of the hidden power of couchapps, and with the Pouch based tools Ddoc Lab
and Inliner that ermouth has made for the site builder and content people, this is a very
low barrier of entry to CouchDB for new developers.


> On 16. okt. 2015, at 14.19, ermouth <> wrote:
> Closing proposal off.
> If someone wants to carry it on, current state is:
> It all works pretty fine and tested, but with own tests, since I was unable
> to overcome CouchDB test set in reasonable time – so no PR.
> Current syntax example:
> rewrites: function(req) {
>  // req is similar to req obj in list fn, but without .id, .info, .uuid,
> .form
>  return {
>   // path is mandatory
>   path:"/some/path?with=query&some=params",
>   // other fields are optional
>   headers:{/*headers go here*/},
>   method:"POST",
>   code:404,
>   body:JSON.stringify([1,2,3])
>  }
> }
> ermouth

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