Skip to content

Instantly share code, notes, and snippets.

@markc
Created April 2, 2011 05:19
Show Gist options
  • Save markc/899249 to your computer and use it in GitHub Desktop.
Save markc/899249 to your computer and use it in GitHub Desktop.
serve_cgi
function serve_cgi(filename, res, get, post, method, vhost, port, pinfo, get, sname, uri, droot) {
var env = {
CONTENT_LENGTH: post.length,
CONTENT_TYPE: 'application/x-www-form-urlencoded',
DOCUMENT_ROOT: droot,
GATEWAY_INTERFACE: 'CGI/1.1',
HTTP_HOST: vhost,
QUERY_STRING: get,
REDIRECT_STATUS: '200',
REQUEST_METHOD: method,
REQUEST_URI: uri,
SCRIPT_FILENAME: filename,
SCRIPT_NAME: sname,
SERVER_NAME: vhost,
SERVER_PORT: port,
SERVER_PROTOCOL: 'HTTP/1.1',
SERVER_SOFTWARE: 'Node/'+process.version+' (Nodality/20110402)',
}
var cgi = spawn(filename, [], env);
cgi.stdout.on('data', function (data) {res.write(data, 'binary'); });
cgi.on('exit', function (code) {res.end();});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment