Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle Ngrok better (#1268) #1281

Merged
merged 1 commit into from
May 14, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions taipy/gui/gui.py
Original file line number Diff line number Diff line change
Expand Up @@ -2275,12 +2275,19 @@ def __init_server(self):

def __init_ngrok(self):
app_config = self._config.config
if app_config["run_server"] and app_config["ngrok_token"]: # pragma: no cover
if hasattr(self, "_ngrok"):
# Keep the ngrok instance if token has not changed
if app_config["ngrok_token"] == self._ngrok[1]:
_TaipyLogger._get_logger().info(f" * NGROK Public Url: {self._ngrok[0].public_url}")
return
# Close the old tunnel so new tunnel can open for new token
ngrok.disconnect(self._ngrok[0].public_url)
if app_config["run_server"] and (token := app_config["ngrok_token"]): # pragma: no cover
if not util.find_spec("pyngrok"):
raise RuntimeError("Cannot use ngrok as pyngrok package is not installed.")
ngrok.set_auth_token(app_config["ngrok_token"])
http_tunnel = ngrok.connect(app_config["port"], "http")
_TaipyLogger._get_logger().info(f" * NGROK Public Url: {http_tunnel.public_url}")
ngrok.set_auth_token(token)
self._ngrok = (ngrok.connect(app_config["port"], "http"), token)
_TaipyLogger._get_logger().info(f" * NGROK Public Url: {self._ngrok[0].public_url}")

def __bind_default_function(self):
with self.get_flask_app().app_context():
Expand Down
Loading