single-command startup

app.py now auto-starts the gateway HTTP server in a daemon thread,
so users only need `python app.py` to get everything running. The
gateway calls dispatch_request directly when co-located (local mode)
instead of trying to establish an RNS link to itself. Bookmarklet
hardcoded to localhost:8080. gateway.py still works standalone for
connecting to remote instances.
This commit is contained in:
lichenblankie 2026-03-25 23:01:54 -07:00
parent 7ccaf93404
commit c5d8d350a6
3 changed files with 52 additions and 34 deletions

18
app.py
View file

@ -1,9 +1,12 @@
import os
import time
import threading
import RNS
from http.server import HTTPServer
from db import init_db
from handlers import dispatch_request
from gateway import GatewayState, GatewayHandler, GATEWAY_PORT
APP_NAME = "tinyweb"
ASPECTS = ["server"]
@ -24,6 +27,14 @@ def rns_request_handler(path, data, request_id, link_id, remote_identity, reques
return dispatch_request(data)
def start_gateway(reticulum):
GatewayState.reticulum = reticulum
GatewayState.local_dispatch = dispatch_request
server = HTTPServer(("127.0.0.1", GATEWAY_PORT), GatewayHandler)
thread = threading.Thread(target=server.serve_forever, daemon=True)
thread.start()
def main():
init_db()
reticulum = RNS.Reticulum()
@ -44,10 +55,11 @@ def main():
)
destination.announce()
start_gateway(reticulum)
print(f"TinyWeb Reticulum server running")
print(f"Destination hash: {RNS.prettyhexrep(destination.hash)}")
print(f"Share this hash with clients to connect via gateway.py")
print(f"TinyWeb running!")
print(f"Open http://localhost:{GATEWAY_PORT} in your browser")
print(f"Destination hash: {RNS.prettyhexrep(destination.hash)} (share this so friends can subscribe)")
while True:
time.sleep(1)