-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathmain.py
More file actions
43 lines (32 loc) · 1.07 KB
/
main.py
File metadata and controls
43 lines (32 loc) · 1.07 KB
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
import uvicorn
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from api import MineStatus
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_credentials=True,
allow_origins=["*"], # Allows all origins
allow_methods=["*"], # Allows all methods
allow_headers=["*"], # Allows all headers
)
@app.get("/")
async def _(request: Request):
if host := request.query_params.get("ip"):
return await MineStatus.unclassified(host)
else:
return {"error": "Missing 'ip' parameter"}
@app.get("/java/")
async def _(request: Request):
if host := request.query_params.get("ip"):
return await MineStatus.get_server_stats(host, "java")
else:
return {"error": "Missing 'ip' parameter"}
@app.get("/bedrock/")
async def _(request: Request):
if host := request.query_params.get("ip"):
return await MineStatus.get_server_stats(host, "bedrock")
else:
return {"error": "Missing 'ip' parameter"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0", port=3000)