mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
Enable configuration of the server bind address.
A serverconfig.env (or just environment variables) can be set to override the default bind address/port for the backend. This is passed to the front end as a query parameter.
This commit is contained in:
parent
a70ab8cc1d
commit
baae65919f
1
.gitignore
vendored
1
.gitignore
vendored
@ -14,6 +14,7 @@ env/
|
|||||||
/kneeboards
|
/kneeboards
|
||||||
/liberation_preferences.json
|
/liberation_preferences.json
|
||||||
/state.json
|
/state.json
|
||||||
|
/serverconfig.env
|
||||||
|
|
||||||
/logs/
|
/logs/
|
||||||
/resources/logging.yaml
|
/resources/logging.yaml
|
||||||
|
|||||||
@ -1,11 +1,15 @@
|
|||||||
import axios from "axios";
|
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({
|
export const backend = axios.create({
|
||||||
baseURL: HTTP_URL,
|
baseURL: HTTP_URL,
|
||||||
});
|
});
|
||||||
|
|
||||||
export const WEBSOCKET_URL = "ws://[::1]:1688/eventstream";
|
export const WEBSOCKET_URL = `ws://${backendAddr}/eventstream`;
|
||||||
|
|
||||||
export default backend;
|
export default backend;
|
||||||
|
|||||||
@ -19,16 +19,15 @@ class ServerSettings(BaseSettings):
|
|||||||
# no client/server workflow yet, security has not been a focus.
|
# no client/server workflow yet, security has not been a focus.
|
||||||
server_bind_address: str = "::1"
|
server_bind_address: str = "::1"
|
||||||
|
|
||||||
# If you for some reason change the port, you'll need to also update map.js and
|
# This (and the address) will be passed the the front end as a query parameter.
|
||||||
# client/src/api/backend.ts.
|
|
||||||
server_port: int = 1688
|
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.
|
# Enable to allow cross-origin requests from http://localhost:3000.
|
||||||
cors_allow_debug_server: bool = False
|
cors_allow_debug_server: bool = False
|
||||||
|
|
||||||
|
class Config:
|
||||||
|
env_file = "serverconfig.env"
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
@lru_cache
|
@lru_cache
|
||||||
def get(cls) -> ServerSettings:
|
def get(cls) -> ServerSettings:
|
||||||
|
|||||||
@ -15,6 +15,7 @@ from PySide2.QtWebEngineWidgets import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
from game import Game
|
from game import Game
|
||||||
|
from game.server.settings import ServerSettings
|
||||||
from qt_ui.models import GameModel
|
from qt_ui.models import GameModel
|
||||||
from .model import MapModel
|
from .model import MapModel
|
||||||
|
|
||||||
@ -61,6 +62,12 @@ class QLiberationMap(QWebEngineView):
|
|||||||
url = QUrl.fromLocalFile(
|
url = QUrl.fromLocalFile(
|
||||||
str(Path("resources/ui/map/canvas.html").resolve())
|
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.page.load(url)
|
||||||
self.setPage(self.page)
|
self.setPage(self.page)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user