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:
parent
4320b14441
commit
c5569fd49e
1 changed files with 15 additions and 4 deletions
19
start.py
19
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)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue