Skip to content

Instantly share code, notes, and snippets.

@tjanczuk
Last active July 19, 2016 22:51
Show Gist options
  • Save tjanczuk/95c972754919c268fee5d70c3d5d66c5 to your computer and use it in GitHub Desktop.
Save tjanczuk/95c972754919c268fee5d70c3d5d66c5 to your computer and use it in GitHub Desktop.
var spawn = require('child_process').spawn;
module.exports = function (options, cb) {
return cb (null, function (ctx, req, res) {
res.writeHead(200, 'text/plain');
var env = process.env;
if (Object.keys(ctx.secrets).length > 0) {
env = {};
for (var e in process.env)
env[e] = process.env[e];
for (var s in ctx.secrets)
env[s] = ctx.secrets[s];
}
var child = spawn('bash', ['--norc', '-c', options.script], { env: env });
child.stdout.pipe(res, { end: false });
child.stderr.pipe(res, { end: false });
child.on('close', (code) => res.end('\nExited with code ' + code));
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment