瀏覽代碼

Better client_url handling (#2188)

* Better client_url handling

* fix tests

---------

Co-authored-by: Fred Lefévère-Laoide <90181748+FredLL-Avaiga@users.noreply.github.com>
Dinh Long Nguyen 6 月之前
父節點
當前提交
755abf0d65
共有 4 個文件被更改,包括 10 次插入8 次删除
  1. 1 1
      taipy/gui/_default_config.py
  2. 1 1
      taipy/gui/config.py
  3. 7 5
      taipy/gui/server.py
  4. 1 1
      tests/gui/gui_specific/test_cli.py

+ 1 - 1
taipy/gui/_default_config.py

@@ -46,7 +46,7 @@ default_config: Config = {
     "change_delay": None,
     "chart_dark_template": None,
     "base_url": "/",
-    "client_url": "http://localhost:{port}",
+    "client_url": None,
     "dark_mode": True,
     "dark_theme": None,
     "debug": False,

+ 1 - 1
taipy/gui/config.py

@@ -108,7 +108,7 @@ Config = t.TypedDict(
         "change_delay": t.Optional[int],
         "chart_dark_template": t.Optional[t.Dict[str, t.Any]],
         "base_url": t.Optional[str],
-        "client_url": str,
+        "client_url": t.Optional[str],
         "dark_mode": bool,
         "dark_theme": t.Optional[t.Dict[str, t.Any]],
         "data_url_max_size": t.Optional[int],

+ 7 - 5
taipy/gui/server.py

@@ -317,8 +317,8 @@ class _Server:
         self._host = host
         if port == "auto":
             port = self._get_random_port(port_auto_ranges)
+        server_url = f"http://{host_value}:{port}"
         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
 
@@ -337,12 +337,14 @@ class _Server:
             log = logging.getLogger("werkzeug")
             log.disabled = True
             if not is_running_from_reloader():
-                _TaipyLogger._get_logger().info(f" * Server starting on http://{host_value}:{port}")
+                _TaipyLogger._get_logger().info(f" * Server starting on {server_url}")
             else:
-                _TaipyLogger._get_logger().info(f" * Server reloaded on http://{host_value}:{port}")
-            _TaipyLogger._get_logger().info(f" * Application is accessible at {client_url}")
+                _TaipyLogger._get_logger().info(f" * Server reloaded on {server_url}")
+            if client_url is not None:
+                client_url = client_url.format(port=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(client_url, new=2)
+            webbrowser.open(client_url or server_url, new=2)
         if _is_in_notebook() or run_in_thread:
             self._thread = KThread(target=self._run_notebook)
             self._thread.start()

+ 1 - 1
tests/gui/gui_specific/test_cli.py

@@ -125,7 +125,7 @@ def test_upload_folder(gui: Gui):
 def test_client_url(gui: Gui):
     with patch("sys.argv", ["prog"]):
         gui.run(run_server=False)
-        assert gui._config.config.get("client_url") == "http://localhost:{port}"
+        assert gui._config.config.get("client_url") is None
 
 
 def test_client_url_1(gui: Gui):