aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Skoland <davidskoland@gmail.com>2023-11-20 00:32:44 +0100
committerDavid Skoland <davidskoland@gmail.com>2023-11-20 21:10:04 +0100
commit4664501188f0f4cace7772c0c1b96d0387df7442 (patch)
tree00a168955530bf9a5e3af4614e6cc3305c0dfca7
parent4035a59b4da2c6bd899f4e0bb91d4fbd5a94a7ac (diff)
Fix domain tricks for localhost
-rw-r--r--webAO/master.ts15
1 files changed, 10 insertions, 5 deletions
diff --git a/webAO/master.ts b/webAO/master.ts
index bfd5d34..41a1688 100644
--- a/webAO/master.ts
+++ b/webAO/master.ts
@@ -143,29 +143,34 @@ function processServerlist(serverlist: AOServer[]) {
let port = 0;
let ws_protocol = '';
let http_protocol = '';
- let domain = '';
+ let client_subdomain = '';
if (server.ws_port) {
port = server.ws_port;
ws_protocol = 'ws';
http_protocol = 'http';
- domain = 'insecure';
+ client_subdomain = 'insecure';
}
if (server.wss_port) {
port = server.wss_port;
ws_protocol = 'wss';
http_protocol = 'https';
- domain = 'web';
+ client_subdomain = 'web';
}
+
if (port === 0 || protocol === '') {
console.warn(`Server ${server.name} has no websocket port, skipping`)
continue;
}
+ let hostname = window.location.hostname;
// Replace the first element of the domain with the correct subdomain
const domainElements = window.location.hostname.split('.');
- domainElements[0] = domain;
- let hostname = domainElements.join('.');
+ // If there is only one element, it's typically localhost or something, so don't replace it
+ if (domainElements.length >= 2) {
+ domainElements[0] = client_subdomain;
+ hostname = domainElements.join('.');
+ }
if (window.location.port) {
hostname += `:${window.location.port}`;