Fix port precedence: respect config.json over hardcoded defaults

This commit is contained in:
ComputerTech 2026-03-31 12:21:31 +01:00
parent a35c60ce63
commit af4ac1287c
2 changed files with 5 additions and 13 deletions

View File

@ -2,7 +2,7 @@ import multiprocessing
# Bind address — change to a Unix socket for nginx proxy: # Bind address — change to a Unix socket for nginx proxy:
# bind = 'unix:/tmp/magic.sock' # bind = 'unix:/tmp/magic.sock'
bind = '0.0.0.0:5000' # bind = '0.0.0.0:5000'
# One worker per CPU core, +1. Keep at 2 minimum for SQLite (WAL mode handles # One worker per CPU core, +1. Keep at 2 minimum for SQLite (WAL mode handles
# concurrent reads; writes are serialised at the SQLite layer). # concurrent reads; writes are serialised at the SQLite layer).

View File

@ -237,9 +237,9 @@ def _build_parser() -> argparse.ArgumentParser:
sub.required = True sub.required = True
def _add_server_args(p: argparse.ArgumentParser) -> None: def _add_server_args(p: argparse.ArgumentParser) -> None:
p.add_argument('--host', default='0.0.0.0', metavar='HOST', p.add_argument('--host', default=None, metavar='HOST',
help='Bind address (default: 0.0.0.0)') help='Bind address (default: 0.0.0.0)')
p.add_argument('--port', default=5000, type=int, metavar='PORT', p.add_argument('--port', default=None, type=int, metavar='PORT',
help='Bind port (default: 5000)') help='Bind port (default: 5000)')
p.add_argument('--workers', default=None, type=int, metavar='N', p.add_argument('--workers', default=None, type=int, metavar='N',
help='Worker processes (default: cpu_count + 1, min 2)') help='Worker processes (default: cpu_count + 1, min 2)')
@ -283,16 +283,8 @@ def main() -> None:
# args.host and args.port always have values because of 'default' in ArgumentParser. # args.host and args.port always have values because of 'default' in ArgumentParser.
# We'll re-parse or check the sys.argv. # We'll re-parse or check the sys.argv.
host = default_host host = args.host or default_host or '0.0.0.0'
port = default_port port = args.port or default_port or 5000
# Simple check: if '--host' or '--port' is in sys.argv, use the arg value.
# Otherwise, use the config value.
if '--host' in sys.argv:
host = args.host
if '--port' in sys.argv:
port = args.port
workers = getattr(args, 'workers', None) or default_workers workers = getattr(args, 'workers', None) or default_workers
if args.command == 'start': if args.command == 'start':