-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathadvanture.py
More file actions
46 lines (35 loc) · 1.06 KB
/
advanture.py
File metadata and controls
46 lines (35 loc) · 1.06 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
44
45
46
from fastapi import FastAPI, WebSocket
from fastapi.staticfiles import StaticFiles
from routers.ws_connection import handle_websocket
from fastapi.responses import RedirectResponse
from fastapi.responses import HTMLResponse
import uvicorn
import os
app = FastAPI()
@app.websocket("/ws")
async def websocket_endpoint(websocket: WebSocket):
await handle_websocket(websocket)
# @app.websocket("/ws")
# async def websocket_endpoint(websocket: WebSocket):
# await websocket.accept()
# print("连接成功")
# while True:
# data = await websocket.receive_text()
# await websocket.send_text(f"接收到的消息是:{data}")
# 静态文件配置(注意 directory 路径)
current_dir = os.path.dirname(os.path.abspath(__file__))
static_dir = os.path.join(current_dir, "static")
app.mount(
"/",
StaticFiles(directory=static_dir, html=True),
name="static"
)
if __name__ == "__main__":
uvicorn.run(
"advanture:app",
host="0.0.0.0",
port=8000,
reload=True,
workers=4,
loop="uvloop"
)