Skip to content

Instantly share code, notes, and snippets.

@tjanczuk
Last active Jul 19, 2016
Embed
What would you like to do?
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