iriscouch / fastcgi

Simple, robust node.js web server that runs FastCGI applications
Apache License 2.0
39 stars 13 forks source link

Add request handler method #6

Open Arlen22 opened 8 years ago

Arlen22 commented 8 years ago

I would like to suggest adding a requestHandler object to export which would allow you to mount the application on any compatible request handler. My implementation used a sort of promise object and basically copied the httpd method. It seems like it shouldn't have to be a promise object, but this is how it ended up. It could also be sent in the callback and then you would just call it in your code.

function getHandler(port, host, socket_path, callback){
  var promise = { requestHandler: function(req, res){ throw new Exception("Promised object not ready yet. Check the ready property"); }, ready: false };
  connect_fcgi(socket_path, 0, function(er, socket) {
    if(er)
      return callback(er)

    fcgi_get_values(socket, function(er, values) {
      if(er)
        return callback(er)

      values.FCGI_MPXS_CONNS = values.FCGI_MPXS_CONNS || 0
      LOG.info('FCGI values: %j', values)

      promise.requestHandler = fcgi_handler(port, host, values, socket, socket_path);
      promise.ready = true;
      return callback(null)
    })
  })
}