Skip to content

Commit bb63e02

Browse files
authored
Merge pull request #572 from raghavyuva/fix/malformed-supertokens-connection-uri
fix: malformed supertokens connection uri during ip based installations
2 parents c895ea6 + b6b1ad5 commit bb63e02

File tree

1 file changed

+14
-4
lines changed
  • cli/app/commands/install

1 file changed

+14
-4
lines changed

cli/app/commands/install/run.py

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import re
55
import shutil
66
import subprocess
7+
from urllib.parse import urlparse
78

89
import typer
910
import yaml
@@ -496,13 +497,22 @@ def _show_success_message(self):
496497

497498
def _get_supertokens_connection_uri(self, protocol: str, api_host: str, supertokens_api_port: int, host_ip: str):
498499
protocol = protocol.replace("https", "http")
500+
501+
host_without_port = api_host
502+
503+
if api_host.startswith(("http://", "https://")):
504+
parsed = urlparse(api_host)
505+
host_without_port = parsed.hostname or api_host
506+
elif ":" in api_host:
507+
parts = api_host.rsplit(":", 1)
508+
if len(parts) == 2 and parts[1].isdigit():
509+
host_without_port = parts[0]
510+
499511
try:
500-
ipaddress.ip_address(api_host)
501-
# If api_host is an IP, use the host_ip instead, x.y.z.w:supertokens_api_port
512+
ipaddress.ip_address(host_without_port)
502513
return f"{protocol}://{host_ip}:{supertokens_api_port}"
503514
except ValueError:
504-
# If api_host is not IP rather domain, then use domain:supertokens_api_port
505-
return f"{protocol}://{api_host}:{supertokens_api_port}"
515+
return f"{protocol}://{host_without_port}:{supertokens_api_port}"
506516

507517
def _update_environment_variables(self, env_values: dict) -> dict:
508518
updated_env = env_values.copy()

0 commit comments

Comments
 (0)