diff --git a/.gitignore b/.gitignore index a05b7650..fae8a968 100644 --- a/.gitignore +++ b/.gitignore @@ -14,6 +14,7 @@ env/ /kneeboards /liberation_preferences.json /state.json +/serverconfig.env /logs/ /resources/logging.yaml diff --git a/client/src/api/backend.ts b/client/src/api/backend.ts index 6b5e27fb..70380e3d 100644 --- a/client/src/api/backend.ts +++ b/client/src/api/backend.ts @@ -1,11 +1,15 @@ import axios from "axios"; -export const HTTP_URL = "http://[::1]:1688/"; +const backendAddr = + new URL(window.location.toString()).searchParams.get("server") ?? + "[::1]:1688"; + +export const HTTP_URL = `http://${backendAddr}/`; export const backend = axios.create({ baseURL: HTTP_URL, }); -export const WEBSOCKET_URL = "ws://[::1]:1688/eventstream"; +export const WEBSOCKET_URL = `ws://${backendAddr}/eventstream`; export default backend; diff --git a/game/server/settings.py b/game/server/settings.py index d414271e..fe0ed8df 100644 --- a/game/server/settings.py +++ b/game/server/settings.py @@ -19,16 +19,15 @@ class ServerSettings(BaseSettings): # no client/server workflow yet, security has not been a focus. server_bind_address: str = "::1" - # If you for some reason change the port, you'll need to also update map.js and - # client/src/api/backend.ts. + # This (and the address) will be passed the the front end as a query parameter. server_port: int = 1688 - # Disable to allow requests to be made to the backend without an API key. - require_api_key: bool = True - # Enable to allow cross-origin requests from http://localhost:3000. cors_allow_debug_server: bool = False + class Config: + env_file = "serverconfig.env" + @classmethod @lru_cache def get(cls) -> ServerSettings: diff --git a/qt_ui/widgets/map/QLiberationMap.py b/qt_ui/widgets/map/QLiberationMap.py index a6afe3a3..50e82d0d 100644 --- a/qt_ui/widgets/map/QLiberationMap.py +++ b/qt_ui/widgets/map/QLiberationMap.py @@ -15,6 +15,7 @@ from PySide2.QtWebEngineWidgets import ( ) from game import Game +from game.server.settings import ServerSettings from qt_ui.models import GameModel from .model import MapModel @@ -61,6 +62,12 @@ class QLiberationMap(QWebEngineView): url = QUrl.fromLocalFile( str(Path("resources/ui/map/canvas.html").resolve()) ) + server_settings = ServerSettings.get() + host = server_settings.server_bind_address + if host.startswith("::"): + host = f"[{host}]" + port = server_settings.server_port + url.setQuery(f"server={host}:{port}") self.page.load(url) self.setPage(self.page)