From d82cb81ca7d7c30ce6ed0816362ea0ce089f67b4 Mon Sep 17 00:00:00 2001 From: rekushi <1+rekushi@noreply.flipnote.world> Date: Thu, 29 Oct 2026 04:35:30 +0000 Subject: [PATCH] feat(server): use configurable startup settings Load the listen address and port from settings, print connection guidance and explain startup failures. --- server.py | 36 +++++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/server.py b/server.py index 2f701de..c6de9c3 100644 --- a/server.py +++ b/server.py @@ -4,8 +4,10 @@ from __future__ import annotations import os import sys import time +import socket + +from server_config import load_config -PORT = int(os.environ.get("REXIMEMO_PORT", "8080")) DOCS_ARGUMENT = "docs:enabled" @@ -68,13 +70,41 @@ def create_site(*, docs_enabled=False): def main(): + settings = load_config() + try: + port = int(os.environ.get("REXIMEMO_PORT", settings["port"])) + if not 1024 <= port <= 65535: + raise ValueError + except ValueError as exc: + raise SystemExit("Choose a port between 1024 and 65535 in server-settings.json or REXIMEMO_PORT.") from exc + host = os.environ.get("REXIMEMO_HOST", settings["host"]) docs_enabled = docs_enabled_from_args() reactor, site, log = create_site(docs_enabled=docs_enabled) - log.write("RexiMemo OSE starting on port %d" % PORT) + log.write("%s starting on %s:%d" % (settings["site_name"], host, port)) + log.write("Web client: http://127.0.0.1:%d/" % port) + try: + addresses = sorted({address[4][0] for address in socket.getaddrinfo(socket.gethostname(), None, socket.AF_INET) + if not address[4][0].startswith("127.")}) + except OSError: + addresses = [] + if host in {"0.0.0.0", "::"}: + for address in addresses: + log.write("DSi HTTP proxy: %s, port %d" % (address, port)) + elif host not in {"127.0.0.1", "::1", "localhost"}: + log.write("DSi HTTP proxy: %s, port %d" % (host, port)) + else: + log.write("Listening on this computer only. For a DSi on your network, choose listen address 0.0.0.0 during setup.") + if not settings["setup_complete"]: + log.write("First-run setup is available: python manage.py setup") log.write("DSi mode uses the historical HTTP proxy path; NAS/DNS/auth services are not included.") if docs_enabled: log.write("Built-in documentation enabled at /docs") - reactor.listenTCP(PORT, site) + from twisted.internet.error import CannotListenError + try: + reactor.listenTCP(port, site, interface=host) + except CannotListenError as exc: + log.close() + raise SystemExit(f"Could not listen on {host}:{port}. Another server may already use that port. Stop it or choose another port with: python manage.py setup") from exc try: reactor.run() finally: