Skip to content

Commit 331b9e9

Browse files
committed
Use ROOT_URL instead of endpoint to generate sockjs path
Fixes #67
1 parent e00247f commit 331b9e9

File tree

2 files changed

+28
-22
lines changed

2 files changed

+28
-22
lines changed

lib/server/balancer/utils.js

+4-2
Original file line numberDiff line numberDiff line change
@@ -104,8 +104,10 @@ function _sendSockJsInfo(req, res, cookies) {
104104

105105
var endpointHash = Cluster.discovery.endpointToHash(endpoint);
106106
// when no balancer url is provided,
107-
// using endpoint's absolute path instead of relative path
108-
var balancer = Cluster.discovery.pickBalancer(endpointHash) || endpoint || "";
107+
// using ROOT_URL instead of relative path
108+
var balancer =
109+
Cluster.discovery.pickBalancer(endpointHash) ||
110+
process.env.ROOT_URL;
109111
// add tail backslash if path not end with it
110112
balancer = (/\/$/).test(balancer)? balancer : balancer + '/';
111113

tests/server/balancer/utils.js

+24-20
Original file line numberDiff line numberDiff line change
@@ -407,17 +407,19 @@ function(test) {
407407
var req = {url: "/web/sockjs/info"};
408408
var res = {writeHead: sinon.stub(), end: sinon.stub()};
409409

410-
WithCluster({_uiService: uiService}, function() {
411-
WithDiscovery(discovery, function() {
412-
Balancer._sendSockJsInfo(req, res, cookies);
413-
414-
test.isTrue(discovery.endpointToHash.calledWith(endpoint));
415-
var info = JSON.parse(res.end.firstCall.args[0]);
416-
test.equal(info.base_url, format(endpoint + "/cluster-ddp/%s/web", hash));
417-
test.equal(info.websocket, true);
418-
419-
balancerMock.verify();
420-
balancerMock.restore();
410+
WithNew(process.env, {"ROOT_URL": endpoint}, function() {
411+
WithCluster({_uiService: uiService}, function() {
412+
WithDiscovery(discovery, function() {
413+
Balancer._sendSockJsInfo(req, res, cookies);
414+
415+
test.isTrue(discovery.endpointToHash.calledWith(endpoint));
416+
var info = JSON.parse(res.end.firstCall.args[0]);
417+
test.equal(info.base_url, format(endpoint + "/cluster-ddp/%s/web", hash));
418+
test.equal(info.websocket, true);
419+
420+
balancerMock.verify();
421+
balancerMock.restore();
422+
});
421423
});
422424
});
423425
});
@@ -447,17 +449,19 @@ function(test) {
447449
var req = {url: "/web/sockjs/info"};
448450
var res = {writeHead: sinon.stub(), end: sinon.stub()};
449451

450-
WithCluster({_uiService: uiService}, function() {
451-
WithDiscovery(discovery, function() {
452-
Balancer._sendSockJsInfo(req, res, cookies);
452+
WithNew(process.env, {"ROOT_URL": endpoint}, function() {
453+
WithCluster({_uiService: uiService}, function() {
454+
WithDiscovery(discovery, function() {
455+
Balancer._sendSockJsInfo(req, res, cookies);
453456

454-
test.isTrue(discovery.endpointToHash.calledWith(endpoint));
455-
var info = JSON.parse(res.end.firstCall.args[0]);
456-
test.equal(info.base_url, format(endpoint + "/cluster-ddp/%s/web", hash));
457-
test.equal(info.websocket, true);
457+
test.isTrue(discovery.endpointToHash.calledWith(endpoint));
458+
var info = JSON.parse(res.end.firstCall.args[0]);
459+
test.equal(info.base_url, format(endpoint + "/cluster-ddp/%s/web", hash));
460+
test.equal(info.websocket, true);
458461

459-
balancerMock.verify();
460-
balancerMock.restore();
462+
balancerMock.verify();
463+
balancerMock.restore();
464+
});
461465
});
462466
});
463467
});

0 commit comments

Comments
 (0)