Skip to content

Instantly share code, notes, and snippets.

@dustin
Created September 8, 2011 23:58
Show Gist options
  • Star 4 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dustin/1205139 to your computer and use it in GitHub Desktop.
Save dustin/1205139 to your computer and use it in GitHub Desktop.
A web pipe server.
// Run this somewhere with a command you want to pipe stuff through.
//
// On a machine that needs data processed, run this:
// curl --data-binary @/some/file http://server:port/ > output
var http = require('http');
var spawn = require('child_process').spawn;
// 0 == node, 1 == [this script]
var PORT = parseInt(process.argv[2]);
var CMD = process.argv[3];
if (!CMD) {
console.log("Need a command to run.");
throw("Need a command to run.");
}
var ARGS = process.argv.slice(4);
function handleReq(req, res) {
res.socket.setTimeout(0);
res.writeHead(200, {'Content-Type': 'text/plain'});
var child = spawn(CMD, ARGS);
req.pipe(child.stdin);
child.stdout.pipe(res);
}
http.createServer(handleReq).listen(PORT, "0.0.0.0");
console.log('Server running at http://0.0.0.0:' + PORT + '/ with ', CMD, ARGS);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment