Skip to content

Commit

Permalink
add dynamic client port
Browse files Browse the repository at this point in the history
  • Loading branch information
dinhlongviolin1 committed Sep 30, 2024
1 parent 6ce4d30 commit f34e5d7
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
2 changes: 1 addition & 1 deletion taipy/gui/_default_config.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
"change_delay": None,
"chart_dark_template": None,
"base_url": "/",
"client_url": "http://127.0.0.1:5000",
"client_url": "http://localhost:{port}",
"dark_mode": True,
"dark_theme": None,
"debug": False,
Expand Down
4 changes: 4 additions & 0 deletions taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2412,6 +2412,9 @@ def get_flask_app(self) -> Flask:
return t.cast(Flask, self._server.get_flask())
raise RuntimeError("get_flask_app() cannot be invoked before run() has been called.")

def _get_port(self) -> int:
return self._server.get_port()

def _set_frame(self, frame: t.Optional[FrameType]):
if not isinstance(frame, FrameType): # pragma: no cover
raise RuntimeError("frame must be a FrameType where Gui can collect the local variables.")
Expand Down Expand Up @@ -2777,6 +2780,7 @@ def run(
return self._server.run(
host=app_config.get("host"),
port=app_config.get("port"),
client_url=app_config.get("client_url"),
debug=app_config.get("debug"),
use_reloader=app_config.get("use_reloader"),
flask_log=app_config.get("flask_log"),
Expand Down
6 changes: 6 additions & 0 deletions taipy/gui/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,6 +246,9 @@ def _direct_render_json(self, data):
def get_flask(self):
return self._flask

def get_port(self):
return self._port

def test_client(self):
return t.cast(Flask, self._flask).test_client()

Expand Down Expand Up @@ -286,6 +289,7 @@ def run(
self,
host,
port,
client_url,
debug,
use_reloader,
flask_log,
Expand All @@ -299,6 +303,7 @@ def run(
if port == "auto":
port = self._get_random_port(port_auto_ranges)
self._port = port
client_url = client_url.format(port=port)
if _is_in_notebook() and notebook_proxy: # pragma: no cover
from .utils.proxy import NotebookProxy

Expand All @@ -320,6 +325,7 @@ def run(
_TaipyLogger._get_logger().info(f" * Server starting on http://{host_value}:{port}")
else:
_TaipyLogger._get_logger().info(f" * Server reloaded on http://{host_value}:{port}")
_TaipyLogger._get_logger().info(f" * Application is accessible at {client_url}")
if not is_running_from_reloader() and self._gui._get_config("run_browser", False):
webbrowser.open(f"http://{host_value}{f':{port}' if port else ''}", new=2)
if _is_in_notebook() or run_in_thread:
Expand Down

0 comments on commit f34e5d7

Please sign in to comment.