move host, port and debug to server run function make .env variables writen in CAPS
This commit is contained in:
@@ -22,16 +22,16 @@ import os
|
|||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
load_dotenv(find_dotenv())
|
load_dotenv(find_dotenv())
|
||||||
|
|
||||||
SNAKE = SnakeBuilder.build(os.environ.get("snake", "DummSnake"))
|
|
||||||
|
|
||||||
server = Server(
|
server = Server(
|
||||||
data_path=os.path.dirname(__file__),
|
data_path=os.path.dirname(__file__),
|
||||||
snake=SnakeBuilder.build(os.environ.get("snake", "DummSnake")),
|
snake=SnakeBuilder.build(os.environ.get("SNAKE", "DummSnake")),
|
||||||
port=int(os.environ.get("PORT", "8000")),
|
|
||||||
debug=bool(os.environ.get("debug", False)),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
if os.environ.get("store_game", None):
|
if os.environ.get("STORE_GAME_HISTORY", None):
|
||||||
server.enable_store_game_state()
|
server.enable_store_game_state()
|
||||||
|
|
||||||
server.run()
|
server.run(
|
||||||
|
host=os.environ.get("HOST", "0.0.0.0"),
|
||||||
|
port=int(os.environ.get("PORT", "8000")),
|
||||||
|
debug=bool(os.environ.get("DEBUG", False))
|
||||||
|
)
|
||||||
|
|||||||
+4
-6
@@ -10,9 +10,7 @@ import logging, json, os
|
|||||||
class Server:
|
class Server:
|
||||||
default_snake_config = {"apiversion":"1","author":"","color":"#888888","head":"default","tail":"default"}
|
default_snake_config = {"apiversion":"1","author":"","color":"#888888","head":"default","tail":"default"}
|
||||||
|
|
||||||
def __init__(self, data_path:str, snake:TemplateSnake, host:str="0.0.0.0", port:str="8000", debug:bool=False):
|
def __init__(self, data_path:str, snake:TemplateSnake, debug:bool=False):
|
||||||
self.host = host
|
|
||||||
self.port = port
|
|
||||||
self.debug = debug
|
self.debug = debug
|
||||||
self.snake = snake
|
self.snake = snake
|
||||||
|
|
||||||
@@ -50,11 +48,11 @@ class Server:
|
|||||||
)
|
)
|
||||||
return response
|
return response
|
||||||
|
|
||||||
def run(self):
|
def run(self, host:str="0.0.0.0", port:str="8000", debug:bool=False):
|
||||||
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
logging.getLogger("werkzeug").setLevel(logging.ERROR)
|
||||||
|
|
||||||
print(f"\nRunning Battlesnake at http://{self.host}:{self.port} with the {self.snake.__class__.__name__.replace('Snake', '')} Snake")
|
print(f"\nRunning Battlesnake at http://{host}:{port} with the {self.snake.__class__.__name__.replace('Snake', '')} Snake")
|
||||||
self.app.run(host=self.host, port=self.port, debug=self.debug)
|
self.app.run(host=host, port=port, debug=debug)
|
||||||
|
|
||||||
def _read_json_config_or_create(self):
|
def _read_json_config_or_create(self):
|
||||||
snake_config = read_file(self.config_file, json.load)
|
snake_config = read_file(self.config_file, json.load)
|
||||||
|
|||||||
Reference in New Issue
Block a user