Updates
This commit is contained in:
16
app.py
16
app.py
@@ -189,17 +189,17 @@ class Room:
|
|||||||
rooms: dict[str, Room] = {}
|
rooms: dict[str, Room] = {}
|
||||||
|
|
||||||
|
|
||||||
API_ROOT = "http://127.0.0.1:8080"
|
API_ROOT = "http://127.0.0.1:8989"
|
||||||
|
|
||||||
|
|
||||||
@app.GET("/")
|
@app.GET("/")
|
||||||
async def home(request):
|
async def home(request):
|
||||||
return render("index.html", {"API_ROOT": API_ROOT})
|
return render(request, "index.html", {"API_ROOT": API_ROOT})
|
||||||
|
|
||||||
|
|
||||||
@app.GET("/<id>")
|
@app.GET("/<id>")
|
||||||
async def home_with_id(request, id):
|
async def home_with_id(request, id):
|
||||||
return render("index.html", {"API_ROOT": API_ROOT})
|
return render(request, "index.html", {"API_ROOT": API_ROOT})
|
||||||
|
|
||||||
|
|
||||||
@app.POST("/join/<room_id>")
|
@app.POST("/join/<room_id>")
|
||||||
@@ -210,6 +210,7 @@ async def join(request, room_id):
|
|||||||
player = room.add_player()
|
player = room.add_player()
|
||||||
if player:
|
if player:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
|
request,
|
||||||
{
|
{
|
||||||
"code": "JOIN",
|
"code": "JOIN",
|
||||||
"id": player[0],
|
"id": player[0],
|
||||||
@@ -217,11 +218,12 @@ async def join(request, room_id):
|
|||||||
"turn": room.turn.value,
|
"turn": room.turn.value,
|
||||||
"board": room.board.serialize(),
|
"board": room.board.serialize(),
|
||||||
"ready": len(room.players) == 2,
|
"ready": len(room.players) == 2,
|
||||||
}
|
},
|
||||||
)
|
)
|
||||||
else:
|
else:
|
||||||
return JSONResponse(
|
return JSONResponse(
|
||||||
{"code": "FULL", "error": "Room Full", "board": room.board.serialize()}
|
request,
|
||||||
|
{"code": "FULL", "error": "Room Full", "board": room.board.serialize()},
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
@@ -509,11 +511,11 @@ async def static(request, fn):
|
|||||||
try:
|
try:
|
||||||
path = sanitize_filename(fn, Path("static/").resolve())
|
path = sanitize_filename(fn, Path("static/").resolve())
|
||||||
return (
|
return (
|
||||||
HTTPResponse("", content_type="application/octet-stream")
|
HTTPResponse(request, "", content_type="application/octet-stream")
|
||||||
+ path.read_bytes()
|
+ path.read_bytes()
|
||||||
)
|
)
|
||||||
except Exception:
|
except Exception:
|
||||||
return HTTPResponse("404 File Not Found", status=404)
|
return HTTPResponse(request, "404 File Not Found", status=404)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
2
libs
2
libs
Submodule libs updated: 9947e2b429...014cdd80e2
Reference in New Issue
Block a user