I struggle mightily tonight in my understanding of fab.js. I am trying to drive access to a particular URL in fab.js. Again, I start with a simple skeleton app that 404s no matter what:
var puts = require( "sys" ).puts;I would like to access a particular document in my CouchDB database based various parameters. To access the DB directly, I can:
with ( require( ".." ) )
( fab )
( listen, 0xFAB )
// code here
( 404 );
( /^\/couch/ )To change that based on inputs, I ought to be able to supply the request from an upstream application. To my mind, this ought to work:
( fab.nodejs.http, "http://localhost:5984/test" )
( /^\/couch/ )The anonymous app that I supply upstream is a unary app (has no arguments), so it ought to serve as a termination point for the request. I squirrel away the downstream app in the
( fab.nodejs.http )
( function () {
puts("here");
var out = this;
puts("here2");
return function(head) {
puts("here3");
out = out({body:'http://localhost:5984/seed'});
if (out) out();
}
} )
out
variable. Then I return a listener that will supply information back to the downstream app. When I run the script and access a /couch
resource:cstrom@whitefall:~/repos/fab$ curl localhost:4011/couch/seed -i -n...I see this print-stderr debugging output:
cstrom@whitefall:~/repos/fab$ node ./play/new_stuff.jsThe listener is never being called ("here3").
here!
here
Hey. Wait a second. Why would I need a listener here? I am not waiting for more information from downstream (closer to the client). I need to respond directly. Could it be that all I need is:
with ( require( ".." ) )Holy crap! Indeed that is all I need to do:
( fab )
( listen, 0xFAB )
( /^\/couch/ )
( fab.nodejs.http )
( function () {
var out = this({body:'http://localhost:5984/seed'});
if (out) out();
} )
( 404 );
cstrom@whitefall:~/repos/fab$ curl localhost:4011/couch/seedI was making this more complicated than it needed to be. All that was required was a "normal" response from the upstream app. No listener or anything else. Nice.
{"db_name":"seed","doc_count":11,"doc_del_count":0,"update_seq":126,"purge_seq":0,"compact_running":false,"disk_size":1450075,"instance_start_time":"1272333640753831","disk_format_version":4}
Day #85
No comments:
Post a Comment