Comparing version 1.4.6 to 1.5.0
'use strict' | ||
var parseURL = require('url').parse, | ||
var parseJSURL = require('jsurl').tryParse, | ||
_ = require('lodash'), | ||
spawn = require('child_process').spawn, | ||
@@ -15,13 +16,17 @@ exec = require('child_process').exec; | ||
module.exports = function (req, res) { | ||
var query = parseURL(req.url,true).query; | ||
if (!query.id) return resEndJSON(res, 400, 'Bad Request'); | ||
if (query.exec) { | ||
exec(query.exec, function (err, stdout, stderr) { | ||
module.exports = function (opts, res) { | ||
var body = parseJSURL(opts['~']); | ||
if (body) { | ||
delete opts['~']; | ||
opts = _.merge(body, opts); | ||
} | ||
if (!opts.id) return resEndJSON(res, 400, 'Bad Request'); | ||
if (opts.exec) { | ||
exec(opts.exec, function (err, stdout, stderr) { | ||
if (err) return resEndJSON(res, 500, err); | ||
resEndJSON(res, 200, {"success":true,"id":query.id,"done":true,"data":stdout||''}); | ||
resEndJSON(res, 200, {"success":true,"opts":opts,"stdout":stdout}); | ||
}); | ||
} else if (query.file) { | ||
} else if (opts.file) { | ||
var stdout = ''; | ||
var child = spawn(query.file, JSON.parse(query.args||'[]')); | ||
var child = spawn(opts.file, opts.args||[]); | ||
child.stdout.on('data', function (data) { | ||
@@ -34,13 +39,7 @@ stdout += data.toString(); | ||
child.on('close', function (code) { | ||
if (code === 0) { | ||
resEndJSON(res, 200, {"success":true,"id":query.id,"done":true,"data":stdout||''}); | ||
} else { | ||
var errObj = new Error('ERROR: process exited with code ' + code); | ||
errObj.code = code; | ||
resEndJSON(res, 500, errObj); | ||
} | ||
resEndJSON(res, 200, {"success":code===0,"opts":opts,"code":code,"stdout":stdout}); | ||
}); | ||
} else { | ||
resEndJSON(res, 200, {"success":true,"id":query.id}); | ||
resEndJSON(res, 200, {"success":false,"opts":opts}); | ||
} | ||
}; |
@@ -19,8 +19,6 @@ 'use strict' | ||
if ('/api/' === request.url.substring(0, 5)) { | ||
if (opts.requireKey) { | ||
var query = parseURL(request.url, true).query | ||
if (opts.requireKey !== query.key) return res404(response) | ||
} | ||
var query = parseURL(request.url, true).query | ||
if (opts.requireKey && opts.requireKey !== query.key) return res404(response) | ||
if (opts.enableRSS && /^\/?api\/1\/rss\.json\?/.test(request.url)) return doRSS(request, response) | ||
if (opts.enableRUN && /^\/?api\/1\/run\.json\?/.test(request.url)) return doRUN(request, response) | ||
if (opts.enableRUN && /^\/?api\/1\/run\.json\?/.test(request.url)) return doRUN(query, response) | ||
} | ||
@@ -27,0 +25,0 @@ var uriMatch = request.url.match('^/?(?://(https?):)?/?(/[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}/.*)$') |
{ | ||
"name": "bfn-proxy", | ||
"version": "1.4.6", | ||
"version": "1.5.0", | ||
"description": "HTTP request proxy middleware for node.js", | ||
@@ -22,7 +22,8 @@ "author": "Blue Fidelity Inc. (https://www.bluefidelity.com/)", | ||
"dependencies": { | ||
"lodash.omit": "^4.5.0", | ||
"iconv-lite": "^0.4.24", | ||
"feedparser": "^2.2.10", | ||
"html-to-text": "^5.1.1", | ||
"iconv-lite": "^0.4.24", | ||
"jsurl": "^0.1.5", | ||
"lodash": "^4.17.11", | ||
"lodash.omit": "^4.5.0", | ||
"logfmt": "~0.21.0", | ||
@@ -29,0 +30,0 @@ "request": "^2.88.0" |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
23749
8
439
+ Addedjsurl@^0.1.5
+ Addedjsurl@0.1.5(transitive)