add bootstrap script to start the server up the same way
This commit is contained in:
@@ -0,0 +1,39 @@
|
||||
from typing import TypedDict
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
from server.Server import Server
|
||||
|
||||
class RunConfig(TypedDict):
|
||||
host: str
|
||||
port: int
|
||||
debug: bool
|
||||
|
||||
def env_bool(name:str, default:bool=False) -> bool:
|
||||
value = os.environ.get(name)
|
||||
if value is None:
|
||||
return default
|
||||
return value.lower() in {'1', 'true', 'yes', 'on'}
|
||||
|
||||
def build_server_from_env(default_snake_type:str) -> Server:
|
||||
data_path = str(Path(__file__).resolve().parent.parent)
|
||||
server = Server(
|
||||
data_path=data_path,
|
||||
snake_type=os.environ.get('SNAKE', default_snake_type),
|
||||
storage_type=os.environ.get('STORAGE', 'LocalStorage'),
|
||||
debug=env_bool('DEBUG_SERVER'),
|
||||
check_tls_security=False,
|
||||
)
|
||||
|
||||
if env_bool('STORE_GAME_HISTORY'):
|
||||
server.enable_store_game_state()
|
||||
|
||||
return server
|
||||
|
||||
|
||||
def build_run_config() -> RunConfig:
|
||||
return {
|
||||
'host': os.environ.get('HOST', '0.0.0.0'),
|
||||
'port': int(os.environ.get('PORT', '8000')),
|
||||
'debug': env_bool('DEBUG'),
|
||||
}
|
||||
Reference in New Issue
Block a user