Skip to content

Commit d4bf2a1

Browse files
author
epriestley
committedApr 14, 2016
Make paths and Aphlict instance names less ambiguous
Summary: Fixes T10783 (what little of it remains). Ref T10697. Aphlict currently uses request paths for two different things: - multi-tenant instancing in the Phacility cluster (each instance gets its own namespace within an Aphlict server); - some users configure nginx and apache to do proxying or SSL termination based on the path. Currently, these can collide. Put a "~" before the instance name to make it unambiguous. At some point we can possibly just use a GET parameter, but I think there was some reason I didn't do that originally and this sequence of changes is disruptive enough already. Test Plan: Saw local Aphlict unambiguously recognize "local.phacility.com" as instance "local", with a "~"-style URI. Reviewers: chad Reviewed By: chad Maniphest Tasks: T10697, T10783 Differential Revision: https://secure.phabricator.com/D15705
1 parent 2930733 commit d4bf2a1

File tree

2 files changed

+22
-7
lines changed

2 files changed

+22
-7
lines changed
 

‎src/applications/notification/client/PhabricatorNotificationServerRef.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,7 @@ public function getURI($to_path = null) {
162162
public function getWebsocketURI($to_path = null) {
163163
$instance = PhabricatorEnv::getEnvConfig('cluster.instance');
164164
if (strlen($instance)) {
165-
$to_path = $to_path.$instance.'/';
165+
$to_path = $to_path.'~'.$instance.'/';
166166
}
167167

168168
$uri = $this->getURI($to_path);

‎support/aphlict/server/lib/AphlictClientServer.js

+21-6
Original file line numberDiff line numberDiff line change
@@ -52,18 +52,33 @@ JX.install('AphlictClientServer', {
5252
response.end('HTTP/501 Use Websockets\n');
5353
},
5454

55+
_parseInstanceFromPath: function(path) {
56+
// If there's no "~" marker in the path, it's not an instance name.
57+
// Users sometimes configure nginx or Apache to proxy based on the
58+
// path.
59+
if (path.indexOf('~') === -1) {
60+
return 'default';
61+
}
62+
63+
var instance = path.split('~')[1];
64+
65+
// Remove any "/" characters.
66+
instance = instance.replace(/\//g, '');
67+
if (!instance.length) {
68+
return 'default';
69+
}
70+
71+
return instance;
72+
},
73+
5574
listen: function() {
5675
var self = this;
5776
var server = this._server.listen.apply(this._server, arguments);
5877
var wss = new WebSocket.Server({server: server});
5978

6079
wss.on('connection', function(ws) {
61-
var instance = url.parse(ws.upgradeReq.url).pathname;
62-
63-
instance = instance.replace(/\//g, '');
64-
if (!instance.length) {
65-
instance = 'default';
66-
}
80+
var path = url.parse(ws.upgradeReq.url).pathname;
81+
var instance = self._parseInstanceFromPath(path);
6782

6883
var listener = self.getListenerList(instance).addListener(ws);
6984

0 commit comments

Comments
 (0)
Failed to load comments.