fix: urlToApi falls back to location.host in single-server case

When ZM_SERVER_ID is unset, Servers[0] is a synthetic default whose
Hostname/Port come from PHP fallbacks (HTTP_HOST, HTTP_X_FORWARDED_PORT,
ZM_BASE_URL) which can disagree with the host:port the browser is
actually using. That caused montagereview XHR to land on the wrong
physical server (e.g. default :443 of a hostname where ZM lives on :81).

For Servers without an Id, derive host:port from location.host so XHR
follows the same connection as the UI. Multi-server entries with a real
Id keep using their configured Hostname/Port.
This commit is contained in:
Isaac Connor
2026-05-08 10:10:20 -04:00
parent c4073c964c
commit 0950131b2a

View File

@@ -45,7 +45,13 @@ var Server = function() {
key: 'urlToApi',
value: function urlToApi() {
const port = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : 0;
return (location.protocol=='https:'? 'https:' : this.Protocol+':') + '//' + this.Hostname + (port ? ':' + port : (this.Port ? ':' + this.Port : (location.port ? ':' + location.port : ''))) + ((this.PathToApi && (this.PathToApi != 'null')) ? this.PathToApi : '');
const protocol = (location.protocol == 'https:' ? 'https:' : this.Protocol + ':');
const path = (this.PathToApi && (this.PathToApi != 'null')) ? this.PathToApi : '';
// Single-server: match browser's host:port (this.Hostname/Port may be wrong behind a proxy).
if (!this.Id) {
return protocol + '//' + location.host + path;
}
return protocol + '//' + this.Hostname + (port ? ':' + port : (this.Port ? ':' + this.Port : (location.port ? ':' + location.port : ''))) + path;
}
},
{