incubator-couchdb-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Zachary Zolton <zachary.zol...@gmail.com>
Subject Re: Setting default values on create server side
Date Fri, 08 Apr 2011 17:28:34 GMT
Update handlers have no intelligent decoding of the request body, if
it's supposed to be JSON then call JSON.parse() on it.

On Fri, Apr 8, 2011 at 4:24 AM, Jeroen van Dijk
<jeroentjevandijk@gmail.com> wrote:
> Hi all,
>
> I'm having troubles setting default values on new documents and have
> everything work like it would normally work.
>
> I have created a simple couchapp with the following rewrite rule:
>
> { "from": "api/v1/apps",
>  "to" : "../zwapp-relax/_update/callbacks",
>  "method": "POST"
>  },
>
> This will trigger the callbacks function which should set the created_at
> value:
>
> function(doc, req) {
>  var newDoc = req.body;
>  newDoc._id = req.uuid
>  newDoc.created_at = 1;
>
>  return [newDoc,"OK"];
> }
>
> Everything seems to work but req.body is not parsed as JSON even though I'm
> setting the header 'Content-Type' to 'application/json'. req.body is just a
> string. When I remove the _update/callbacks part from the rewrite I
> get "reason":"Referer header required."
>
> Any idea of what I'm doing wrong or how I should approach setting default
> values server side?
>
> Thanks,
>
> Jeroen
>
> PS. The answer to this question also implies there are some difficulties
> doing the above:
> http://stackoverflow.com/questions/3009925/couchdb-automatic-timestamps
>

Mime
View raw message