Skip to content

Commit

Permalink
Added the ability to disable port (#210)
Browse files Browse the repository at this point in the history
* Added the ability to disable port from being added so that users that have server redirects via nginx can use it

* restrict canonicalize_url to webui process

---------

Co-authored-by: ljleb <[email protected]>
  • Loading branch information
trpipher and ljleb authored Feb 1, 2024
1 parent ac6ec6a commit 10e95a4
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions lib_comfyui/webui/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ def create_section():
shared.opts.onchange("comfyui_reverse_proxy_enabled", update_reverse_proxy_enabled)
update_reverse_proxy_enabled()

shared.opts.add_option("comfyui_reverse_proxy_disable_port", shared.OptionInfo(False,'Disable using the port when using reverse_proxy. Useful if using a nginx server',section=section))


@ipc.restrict_to_process('webui')
def update_enabled():
Expand Down Expand Up @@ -159,9 +161,10 @@ def get_comfyui_client_url():
return client_url


@ipc.restrict_to_process('webui')
def canonicalize_url(input_url: str, default_port: int = 8189) -> str:
from urllib.parse import urlparse, urlunparse

from modules import shared
# Step 1: Prepend 'http://' if scheme is missing
if not input_url.startswith(('http://', 'https://')):
input_url = 'http://' + input_url
Expand All @@ -173,8 +176,9 @@ def canonicalize_url(input_url: str, default_port: int = 8189) -> str:
scheme = parsed.scheme if parsed.scheme else 'http'

# Step 4: Add the missing port
disable_port = shared.opts.data.get('comfyui_reverse_proxy_disable_port',False)
netloc = parsed.netloc
if ':' not in netloc: # Check if port is missing
if ':' not in netloc and not disable_port: # Check if port is missing
netloc += f":{default_port}"
elif netloc.count(':') == 1 and parsed.scheme: # If port exists but scheme was present in input
host, port = netloc.split(':')
Expand Down

0 comments on commit 10e95a4

Please sign in to comment.