Skip to content

Instantly share code, notes, and snippets.

@kieran
Created May 17, 2010 00:13
Show Gist options
  • Save kieran/403271 to your computer and use it in GitHub Desktop.
Save kieran/403271 to your computer and use it in GitHub Desktop.
** It should be noted that I'm by no means even remotely competent, especially in JS.
Design goals:
load as little as possible, as infrequently as possible
avoid the overhead of forking a new process for each request
..and having to manage these processes - Merb workers go rogue all the time, which is annoying as hell
take advantage of the already sandboxey nature of v8
clean up the application global namespace a little
protect Geddy's global namespace from getting clobbered
use whatever libraries / core extensions in either Geddy OR the app without fear of conflicts
Geddy:
utils // opts parser, inflections, etc...
plugins // db adapter, session store, template engines, etc...
// load app code (see App below)
httpServer.start() // & set up event listeners
App:
app = new Script(config_hash, 'app.js') // sets config, compiles routes, waits as bytecode to be executed with params
When a request comes in:
sandbox.params = utils.parse(params) // parse params
sandbox.session = plugins.session.load()
sandbox.request = client.request
sandbox.response = { headers:null, body:null, code:null }
// etc.....
app.runInNewContext(sandbox)
client.send(sandbox.response) // dump response down the pipe
When files in the app directory change:
app = new Script(config_hash, 'app.js') // next request will use the new, pre-compiled app code object
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment