From 9f63e687b6c715b1169097220dac29c05807eb07 Mon Sep 17 00:00:00 2001 From: thmsn <9084377+thmsndk@users.noreply.github.com> Date: Sun, 4 Aug 2024 08:47:27 +0200 Subject: [PATCH] Map servers by region and server name `EUI` instead of ip due to docker changing internal ip at will --- api.py | 4 +++- useful/template.environment.py | 12 ++++++++---- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/api.py b/api.py index d41298d5..41fc2104 100644 --- a/api.py +++ b/api.py @@ -1497,9 +1497,11 @@ def create_server_api(**args): actual_ip=ip=request.remote_addr; server_name="XX" if is_sdk: # The ip we store should be the url the client needs to use - ip = "%s"%(environment.REQUEST_IP_TO_HOSTNAME.get(ip,ip)) + mappingKey = "%s%s"%(region,sname) + ip = "%s"%(environment.CREATE_SERVER_MAPPING.get(mappingKey,ip)) # If we are not running in HTTPS_MODE servers_to_client will use actual_ip instead actual_ip = ip + logging.info("create_server_api: sname: %s region:%s %s %s"%(sname,region,ip,actual_ip)) # TODO: makes an ip like eu1.adventure.land, this is hardcoded and should be changed if domain.https_mode: ip="%s.%s"%(ip_to_subdomain.get(ip,ip),live_domain) diff --git a/useful/template.environment.py b/useful/template.environment.py index b2c3fa80..799d7bee 100644 --- a/useful/template.environment.py +++ b/useful/template.environment.py @@ -15,8 +15,12 @@ "158.69.23.127":"usd1" } -# This is currently only used in SDK mode to map the hostname -REQUEST_IP_TO_HOSTNAME = { - "172.20.0.4":"localhost", #EU1 docker internal ip - "172.20.0.3":"localhost", #US1 docker internal ip +# This is responsible for mapping the correct ip/domain that the client should use to connect with in the websocket +CREATE_SERVER_MAPPING = { + + # example of how thmsn.adventureland.community works + # "EUI": "eu1.thmsn.adventureland.community" + + # When running a local test server on your private machine + "EUI": "localhost" } \ No newline at end of file