-
Notifications
You must be signed in to change notification settings - Fork 382
/
server.py
46 lines (35 loc) · 1.03 KB
/
server.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import logging
import os
import typing
from flask import Flask
from flask import request
def run_server(handlers: typing.Dict):
app = Flask("Battlesnake")
@app.get("/")
def on_info():
return handlers["info"]()
@app.post("/start")
def on_start():
game_state = request.get_json()
handlers["start"](game_state)
return "ok"
@app.post("/move")
def on_move():
game_state = request.get_json()
return handlers["move"](game_state)
@app.post("/end")
def on_end():
game_state = request.get_json()
handlers["end"](game_state)
return "ok"
@app.after_request
def identify_server(response):
response.headers.set(
"server", "battlesnake/github/starter-snake-python"
)
return response
host = "0.0.0.0"
port = int(os.environ.get("PORT", "8000"))
logging.getLogger("werkzeug").setLevel(logging.ERROR)
print(f"\nRunning Battlesnake at http://{host}:{port}")
app.run(host=host, port=port)