diff --git a/modules/proxy.js b/modules/proxy.js index 3de5115..9876478 100644 --- a/modules/proxy.js +++ b/modules/proxy.js @@ -33,7 +33,7 @@ function parseEntry(entry) { return entry; } -var proxy = httpProxy.createProxyServer({agent: null, xfwd: true}); +var proxy = httpProxy.createProxyServer({xfwd: true}); var regexpHelper = require('../regexpHelper'); var proxyFailErrorHandler; diff --git a/package.json b/package.json index 57d3420..21e96ab 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "http-master", - "version": "0.7.7", + "version": "0.7.8", "description": "Easy to setup, convenient, universal, parallel, http/https proxy daemon. Setup in 1 minute, run, configure, adapt. Proxying based on excellent node-http-proxy.", "main": "master.js", "scripts": { @@ -22,21 +22,22 @@ ], "license": "BSD", "dependencies": { - "http-proxy": "~1.0.1", - "optimist": "~0.6.0", "async": "~0.2.9", - "extend": "~1.2.1", + "bugsnag": "~1.2", "es6-shim": "~0.9.2", + "extend": "~1.2.1", + "http-auth": "~2.1.6", + "http-proxy": "^1.1.2", + "js-yaml": "~3.0.1", "jsonlint-lines": "~1.6.0", + "moment": "^2.6.0", "node-static": "~0.7.2", "node-watch": "~0.3.4", + "optimist": "~0.6.0", "spdy": "~1.17.22", "uid-number": "0.0.3", "x509": "git://github.com/CodeCharmLtd/node-x509#parse-pem", - "js-yaml": "~3.0.1", - "http-auth": "~2.1.6", - "xregexp": "~2.0.0", - "moment": "^2.6.0" + "xregexp": "~2.0.0" }, "devDependencies": { "istanbul": "~0.2.7", diff --git a/tests/bugsnagTest.js b/tests/bugsnagTest.js new file mode 100644 index 0000000..babbb9f --- /dev/null +++ b/tests/bugsnagTest.js @@ -0,0 +1,90 @@ +var net = require('net'); +var http = require('http'); +var async = require('async'); +var HttpMasterWorker = require('../workerLogic'); +var url = require('url'); +var parseUrl = url.parse.bind(url); +var should = require('should'); +var assert = require('assert'); + + +var startTester = function(portConfig, targetPort, handler) { + var worker = new HttpMasterWorker(); + worker.loadConfig({ + ports: { + 40880: portConfig + } + }, function(err) { + assert(!err); + }); + var httpServer = http.createServer(); + httpServer.listen(targetPort); + + return { + server: httpServer, + request: function(url, requestFinish, resValidator, reqValidator) { + var parsedUrl = parseUrl(url); + + var options = { + host: 'localhost', + port: 40880, + path: parsedUrl.path, + method: 'GET', + headers: { + host: parsedUrl.host + } + }; + + httpServer.once('request', function(req, res) { + if (reqValidator) { + reqValidator(req); + } else { + req.headers.host.should.equal(parsedUrl.hostname); + req.url.should.equal(parsedUrl.path); + } + res.statusCode = 404; + res.end('Sorry'); + }); + + var req = http.request(options, function(res) { + if (resValidator) { + resValidator(res, req); + } else { + res.statusCode.should.equal(404); + } + res.on('error', requestFinish); + + res.on('data', function(data) { + data.toString().should.equal(string); + requestFinish(); + }); + }); + + req.string = 'Sorry'; + req.on('error', requestFinish); + req.end(); + }, + finish: function() { + worker.loadConfig({}); + httpServer.close(); + } + }; +}; + + +describe('Bugsnag Test', function() { + it('should redirect multiple requests', function(finished) { + var tester = startTester({ + redirect: { + "*": 'http://[1]:40881/[path]' + } + }, 40881); + + tester.request('http://example.com/path/?query_param=true', finished, function (res, req) { + res.statusCode.should.equal(302); + + tester.finish(); + finished(); + }); + }); +}); diff --git a/tests/proxy.js b/tests/proxy.js index 8b51a0f..8e2e258 100644 --- a/tests/proxy.js +++ b/tests/proxy.js @@ -40,11 +40,14 @@ function unpatchProxyServer() { patchProxyServer(); +delete require.cache[require.resolve('../modules/proxy')]; var proxy = require('../modules/proxy'); delete require.cache[require.resolve('../modules/proxy')]; // clear the patched module from cache so that other tests can // resolve unpatched module -unpatchProxyServer(); +//unpatchProxyServer(); + + var middleware; diff --git a/worker.js b/worker.js index 81864bd..f8926a7 100644 --- a/worker.js +++ b/worker.js @@ -73,12 +73,26 @@ process.sendMessage = function(type, data) { }; process.on('message', function(msg) { - var msg = JSON.parse(msg); + msg = JSON.parse(msg); process.emit('msg:' + msg.type, msg.data); }); process.on('uncaughtException', function(err) { logError("[Uncaught exception] " + err.stack || err.message); + +// TODO: Draft implementation of Bugsnag +// var bugsnag = require('bugsnag'); +// bugsnag.register("your-api-key-here", { +// autoNotifyUncaught: false, +// useSSL: true +// }); +// bugsnag.notify(err, { +// context: 'worker', +// userId: request.ip, +// request: requestObject +// // metaData: requestObject +// }); + process.exit(1); });