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.
This commit is contained in:
DannyDannyDanny 2026-04-24 12:47:16 +02:00
parent 4320b14441
commit c5569fd49e

View file

@ -156,9 +156,17 @@ def main():
print(" Server failed to start!") print(" Server failed to start!")
sys.exit(1) sys.exit(1)
# 3. Start tunnel # 3. Tunnel — skipped if WEBAPP_URL is already provided (e.g. the bot
tunnel, webapp_url = start_tunnel(port) # is fronted by an external reverse proxy that terminates TLS and
procs.append(tunnel) # 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 # 4. Start bot
print(f"\n WEBAPP_URL: {webapp_url}") print(f"\n WEBAPP_URL: {webapp_url}")
@ -178,7 +186,10 @@ def main():
for p in procs: for p in procs:
ret = p.poll() ret = p.poll()
if ret is not None: 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}") print(f"\n {name} exited with code {ret}")
cleanup() cleanup()
time.sleep(1) time.sleep(1)