ManiAz09 commited on
Commit
0f64db5
·
verified ·
1 Parent(s): 9295093

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +14 -1
app.py CHANGED
@@ -148,9 +148,22 @@ async def shutdown():
148
  if http_client:
149
  await http_client.aclose()
150
 
151
- def get_domain() -> str:
152
  return os.environ.get("SPACE_HOST", "localhost").replace("https://", "").replace("http://", "")
153
 
 
 
 
 
 
 
 
 
 
 
 
 
 
154
  def generate_uuid(seed: str | None = None) -> str:
155
  # Real, standard RFC-4122 UUID
156
  if seed is None:
 
148
  if http_client:
149
  await http_client.aclose()
150
 
151
+ def get_domain_old() -> str:
152
  return os.environ.get("SPACE_HOST", "localhost").replace("https://", "").replace("http://", "")
153
 
154
+
155
+ def get_domain() -> str:
156
+ import urllib.request
157
+ try:
158
+ # Attempt to get the public IPv4 address first (best for VPN/Proxy links)
159
+ public_ip = urllib.request.urlopen('https://api.ipify.org', timeout=3).read().decode('utf8')
160
+ return public_ip
161
+ except Exception:
162
+ # Fallback to the local interface IPv4 using your existing function
163
+ ipv4, _ = get_real_ips()
164
+ return ipv4 if ipv4 else "127.0.0.1"
165
+
166
+
167
  def generate_uuid(seed: str | None = None) -> str:
168
  # Real, standard RFC-4122 UUID
169
  if seed is None: