Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

integrate with Bugsnag #46 #47

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion modules/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
17 changes: 9 additions & 8 deletions package.json
Original file line number Diff line number Diff line change
@@ -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": {
Expand All @@ -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",
Expand Down
90 changes: 90 additions & 0 deletions tests/bugsnagTest.js
Original file line number Diff line number Diff line change
@@ -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();
});
});
});
5 changes: 4 additions & 1 deletion tests/proxy.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
16 changes: 15 additions & 1 deletion worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
});

Expand Down