views:

113

answers:

1

The quick overview is this: for my web app I can write most of my functionality using CouchApp and CouchDB views, etc. I love the feature of CouchApp that pushes my code up to the server via replication- this makes the deployment cycle very easy.

However, to do some arbitrary work not supported in couchdb and works around a few limitations, I need to put a web platform in front of CouchDB. I'm considering building this in node.js because it uses JavaScript and I want to continue the easy deployment method of pushing code into the database.

Here's how i imagine it working: - I write a web server/service in node.js using the normal method and the node command to start it. - this sevice connects to couch db and gets a virtual list and a URL mapping list. This list is stored in redis for quick lookup. This list will tell the server, when it gets a request, based on host and path, etc, which handler is to be run. - the server fetches the handler- which is just a document, it could be a design document or an arbitrary json document in couchdb. And then executes that handler to handle the request, as if I'd writte the handler as part of node js.

So the question is, how to get a son data structure that contains a JavaScript function in it, in text form, and execute that function?

This may be blindingly obvious, but i come from a compiled background, so normally there would be a compilation step here that makes this pretty much impossible.

So, what I'm thinking is in pseudo code: Var string thecode = getValueForMapKey(handlerFunctionIWant); somehowmagicallyexecute(thecode)

Is there an exec or run function that will do the magical execution step above in JavaScript?

A: 

eval(handlerFunctionIwant) is the call to execute it. You need to make sure that there's no way for hackers to inject code into that string, of course.

It is not clear to me if this will evaluate it in a context that has access to other javescript resources, such as the rest of node.js or access to your couchdb library.

Agent Smith-Jones