From c5569fd49efeeaa2fecd0029ef8a5a8721ed631d Mon Sep 17 00:00:00 2001 From: DannyDannyDanny Date: Fri, 24 Apr 2026 12:47:16 +0200 Subject: [PATCH] start.py: skip cloudflared tunnel when WEBAPP_URL is set in env Allows the bot to run behind an external reverse proxy (e.g. a VPS running Caddy on a public TLS-terminated domain forwarding to localhost:$API_PORT over a private overlay network) instead of spinning up an ephemeral trycloudflare.com quick tunnel. Set WEBAPP_URL=https://your.domain/... in the service environment and start.py will use it verbatim and skip spawning cloudflared. Behavior unchanged when WEBAPP_URL is unset: still launches cloudflared and picks up the auto-generated trycloudflare.com URL as before. --- start.py | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/start.py b/start.py index 2f6352b..2710741 100644 --- a/start.py +++ b/start.py @@ -156,9 +156,17 @@ def main(): print(" Server failed to start!") sys.exit(1) - # 3. Start tunnel - tunnel, webapp_url = start_tunnel(port) - procs.append(tunnel) + # 3. Tunnel — skipped if WEBAPP_URL is already provided (e.g. the bot + # is fronted by an external reverse proxy that terminates TLS and + # proxies back to localhost:$API_PORT over a private network). + env_webapp_url = os.environ.get("WEBAPP_URL", "").strip() + tunnel = None + if env_webapp_url: + webapp_url = env_webapp_url + print(f" WEBAPP_URL from environment: {webapp_url} (skipping cloudflared)") + else: + tunnel, webapp_url = start_tunnel(port) + procs.append(tunnel) # 4. Start bot print(f"\n WEBAPP_URL: {webapp_url}") @@ -178,7 +186,10 @@ def main(): for p in procs: ret = p.poll() if ret is not None: - name = {id(server): "Server", id(tunnel): "Tunnel", id(bot): "Bot"}.get(id(p), "?") + proc_names = {id(server): "Server", id(bot): "Bot"} + if tunnel is not None: + proc_names[id(tunnel)] = "Tunnel" + name = proc_names.get(id(p), "?") print(f"\n {name} exited with code {ret}") cleanup() time.sleep(1)