diff --git a/app/chat/websocket.py b/app/chat/websocket.py index e8cc02e..97d5c0d 100644 --- a/app/chat/websocket.py +++ b/app/chat/websocket.py @@ -1,3 +1,4 @@ +import logging from typing import Annotated import websockets @@ -142,6 +143,7 @@ async def websocket_endpoint( # await AuthService.check_verificated_user_with_exc(uow=uow, user_id=user.id) # await AuthService.validate_user_access_to_chat(uow=uow, user_id=user.id, chat_id=chat_id) await manager.connect(chat_id, websocket) + logging.critical(authorization) await websocket.send_json({"headers": str(websocket.headers), "authorization": authorization}) try: while True: @@ -151,14 +153,15 @@ async def websocket_endpoint( except WebSocketDisconnect: manager.disconnect(chat_id, websocket) -# -# @router.post( -# "/ws/{chat_id}" -# ) -# async def websocket_endpoint( -# chat_id: int, -# token: str = Depends(get_token), -# ): -# url = f"ws://localhost:8000/api/chat/ws/{chat_id}" -# async with websockets.connect(url, extra_headers={"Authorization": f"Bearer {token}"}) as websocket: -# print(await websocket.recv()) + +@router.post( + "/ws/{chat_id}" +) +async def websocket_endpoint( + chat_id: int, + token: str = Depends(get_token), +): + logging.critical("Это сообщение уровня INFO") + url = f"ws://localhost:8000/api/chat/ws/{chat_id}" + async with websockets.connect(url, extra_headers={"Authorization": f"Bearer {token}"}) as websocket: + print(await websocket.recv()) diff --git a/app/users/dependencies.py b/app/users/dependencies.py index 14a2ea4..b6f3f6e 100644 --- a/app/users/dependencies.py +++ b/app/users/dependencies.py @@ -1,6 +1,6 @@ from typing import Annotated -from fastapi import Depends, Header, WebSocket +from fastapi import Depends, Header from fastapi.security import HTTPBearer from jose import JWTError, jwt, ExpiredSignatureError