Configurable back-end port

This commit is contained in:
Raffson
2024-02-10 17:58:44 +01:00
parent 63d05ea696
commit cb68ff0df3
8 changed files with 62 additions and 13 deletions

View File

@@ -2,6 +2,7 @@ import time
from collections.abc import Iterator
from contextlib import contextmanager
from threading import Thread
from typing import Optional
import uvicorn
from uvicorn import Config
@@ -13,12 +14,13 @@ from game.sim import GameUpdateEvents
class Server(uvicorn.Server):
def __init__(self) -> None:
def __init__(self, port: Optional[int]) -> None:
settings = ServerSettings.get(port)
super().__init__(
Config(
app=app,
host=ServerSettings.get().server_bind_address,
port=ServerSettings.get().server_port,
host=settings.server_bind_address,
port=settings.server_port,
# Configured explicitly with default_logging.yaml or logging.yaml.
log_config=None,
)

View File

@@ -1,6 +1,7 @@
from __future__ import annotations
from functools import lru_cache
from typing import Optional
from pydantic_settings import BaseSettings
@@ -30,5 +31,5 @@ class ServerSettings(BaseSettings):
@classmethod
@lru_cache
def get(cls) -> ServerSettings:
return cls()
def get(cls, port: Optional[int] = server_port) -> ServerSettings:
return cls(server_port=port)