Aggiunto un log migliore

This commit is contained in:
2026-07-01 15:17:24 +02:00
parent c1f8f0c8fa
commit f73d5d9164

View File

@@ -58,6 +58,10 @@ def log(message: str) -> None:
print(message, flush=True) print(message, flush=True)
def format_access_url(host: str, port: int) -> str:
return f"http://{host}:{port}"
def get_user_container_lock(user_id: str) -> threading.Lock: def get_user_container_lock(user_id: str) -> threading.Lock:
with user_container_locks_guard: with user_container_locks_guard:
if user_id not in user_container_locks: if user_id not in user_container_locks:
@@ -534,7 +538,11 @@ async def main():
servers = [] servers = []
if GATEWAY_PORT > 0: if GATEWAY_PORT > 0:
gateway_server = await asyncio.start_server(handle_gateway_connection, "0.0.0.0", GATEWAY_PORT) gateway_server = await asyncio.start_server(handle_gateway_connection, "0.0.0.0", GATEWAY_PORT)
log(f"Shared gateway ready on port {GATEWAY_PORT}") log(
"Shared gateway ready: "
f"{format_access_url('localhost', GATEWAY_PORT)} "
"(host-based routing: http://<user>.localhost:{GATEWAY_PORT})"
)
servers.append(gateway_server) servers.append(gateway_server)
for user in config["users"]: for user in config["users"]:
@@ -542,7 +550,15 @@ async def main():
await handle_connection(reader, writer, configured_user) await handle_connection(reader, writer, configured_user)
server = await asyncio.start_server(handler, "0.0.0.0", user["port"]) server = await asyncio.start_server(handler, "0.0.0.0", user["port"])
log(f"Ready on port {user['port']} for user {user['id']} ({user['container_name']})") direct_url = format_access_url("localhost", user["port"])
if GATEWAY_PORT > 0:
gateway_url = format_access_url(f"{user['id']}.localhost", GATEWAY_PORT)
log(
f"Ready for user {user['id']} ({user['container_name']}): "
f"{direct_url} or {gateway_url}"
)
else:
log(f"Ready for user {user['id']} ({user['container_name']}): {direct_url}")
servers.append(server) servers.append(server)
asyncio.create_task(idle_checker()) asyncio.create_task(idle_checker())