Изменения вебсокета
This commit is contained in:
parent
9e39125a99
commit
10d85fe612
1 changed files with 13 additions and 1 deletions
14
app/main.py
14
app/main.py
|
@ -1,6 +1,7 @@
|
|||
from fastapi import FastAPI
|
||||
from fastapi import FastAPI, Request
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from starlette.middleware.base import BaseHTTPMiddleware
|
||||
|
||||
from app.users.router import router as user_router
|
||||
from app.chat.websocket import router as websocket_router
|
||||
|
@ -31,3 +32,14 @@ app.add_middleware(
|
|||
)
|
||||
|
||||
app.mount("/static", StaticFiles(directory="app/static"), name="static")
|
||||
|
||||
|
||||
class AddHeaderMiddleware(BaseHTTPMiddleware):
|
||||
async def dispatch(self, request: Request, call_next):
|
||||
response = await call_next(request)
|
||||
response.headers["Sec-Websocket-Protocol"] = request.headers["Sec-Websocket-Protocol"]
|
||||
return response
|
||||
|
||||
|
||||
app.add_middleware(AddHeaderMiddleware)
|
||||
|
||||
|
|
Loading…
Add table
Reference in a new issue