Untitled diff

Created Diff never expires
23 removals
53 lines
16 additions
48 lines
var path = require('path'),
var path = require('path'),
util = require('util'),
util = require('util'),
querystring = require('querystring'),
querystring = require('querystring'),
child_process = require('child_process');
child_process = require('child_process');


var engine = function (filePath, opts, callback) {
var engine = function (filePath, opts, callback) {
var binPath = this.binPath,
var binPath = this.binPath,
runnerPath = this.runnerPath,
runnerPath = this.runnerPath,
displayErrors = this.displayErrors,


method = opts.method || 'GET',
method = opts.method || 'GET',
get = opts.get || {},
get = opts.get || {},
post = opts.post || {},
post = opts.post || {},


query = opts.query || querystring.stringify(get),
query = opts.query || querystring.stringify(get),
body = opts.body || querystring.stringify(post),


env = {
env = {
REQUEST_METHOD: method,
REQUEST_METHOD: method,
CONTENT_LENGTH: body.length,
QUERY_STRING: query
QUERY_STRING: query
};
},
encodedEnv = [];

for (var key in env) {
if (env[key]) {
encodedEnv.push(util.format('%s="%s"', key, env[key]));
}
}


var command = util.format(
var command = util.format(
'%s %s %s %s',
'%s %s %s %s %s',
(body ? util.format('echo "%s" | ', body) : '') + binPath,
encodedEnv.length ? 'export ' + encodedEnv.join(' ') + ';' : '',
binPath,
runnerPath,
runnerPath,
path.dirname(filePath),
path.dirname(filePath),
filePath
filePath,
(typeof post == "string" ? util.format(" '%s'", post) : '')
);
);

child_process.exec(command, function (error, stdout, stderr) {
child_process.exec(command,{
env: env
}, function (error, stdout, stderr) {
if (error) {
if (error) {

callback(error);
// can leak server configuration
if (displayErrors && stdout) {
callback(stdout);
} else {
callback(error);
}
} else if (stdout) {
} else if (stdout) {
callback(null, stdout);
callback(null, stdout);
} else if (stderr) {
} else if (stderr) {
callback(stderr);
callback(stderr);
} else {
callback(null, null);
}
}
});
});
};
};


module.exports = engine;
module.exports = engine;