Skip to content

Commit

Permalink
Changing app host/IP binding
Browse files Browse the repository at this point in the history
Fix #98
  • Loading branch information
FeodorFitsner committed Aug 2, 2022
1 parent e038dcb commit 1421ec7
Showing 1 changed file with 18 additions and 3 deletions.
21 changes: 18 additions & 3 deletions sdk/python/flet/flet.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@

def page(
name="",
host=None,
port=0,
permissions=None,
view: AppViewer = WEB_BROWSER,
Expand All @@ -48,6 +49,7 @@ def page(
):
conn = _connect_internal(
page_name=name,
host=host,
port=port,
is_app=False,
permissions=permissions,
Expand All @@ -67,6 +69,7 @@ def page(

def app(
name="",
host=None,
port=0,
target=None,
permissions=None,
Expand All @@ -81,6 +84,7 @@ def app(

conn = _connect_internal(
page_name=name,
host=host,
port=port,
is_app=True,
permissions=permissions,
Expand Down Expand Up @@ -133,6 +137,7 @@ def exit_gracefully(signum, frame):

def _connect_internal(
page_name=None,
host=None,
port=0,
is_app=False,
update=False,
Expand All @@ -156,10 +161,11 @@ def _connect_internal(
# page with a custom port starts detached process
attached = False if not is_app and port != 0 else True

server_ip = host if host not in [None, "", "*"] else "127.0.0.1"
port = _start_flet_server(
port, attached, assets_dir, web_renderer, route_url_strategy
host, port, attached, assets_dir, web_renderer, route_url_strategy
)
server = f"http://127.0.0.1:{port}"
server = f"http://{server_ip}:{port}"

connected = threading.Event()

Expand Down Expand Up @@ -226,7 +232,9 @@ def _on_ws_failed_connect():
return conn


def _start_flet_server(port, attached, assets_dir, web_renderer, route_url_strategy):
def _start_flet_server(
host, port, attached, assets_dir, web_renderer, route_url_strategy
):

if port == 0:
port = _get_free_tcp_port()
Expand Down Expand Up @@ -266,6 +274,13 @@ def _start_flet_server(port, attached, assets_dir, web_renderer, route_url_strat
logging.info(f"Assets path configured: {assets_dir}")
fletd_env["FLET_STATIC_ROOT_DIR"] = assets_dir

if host not in [None, "", "*"]:
logging.info(f"Host binding configured: {host}")
fletd_env["FLET_SERVER_IP"] = host

if host != "127.0.0.1":
fletd_env["FLET_ALLOW_REMOTE_HOST_CLIENTS"] = "true"

if web_renderer not in [None, "", "auto"]:
logging.info(f"Web renderer configured: {web_renderer}")
fletd_env["FLET_WEB_RENDERER"] = web_renderer
Expand Down

0 comments on commit 1421ec7

Please sign in to comment.