Files
romm/backend/handler/socket_handler.py
Michael Manganiello b81fbc5820 fix: Improve handling of Redis URL
This change replaces the creation of Redis URL, from a simple string
interpolation, to using `yarl.URL`. The main benefit, besides not
forgetting to set all five different variables on every Redis client
initialization, is that user credentials are correctly URL-encoded, if
present.

Up until now, if a password had special characters, it could break the
generated URL.

This change also introduces support for a `REDIS_SSL` setting, which
allows the user to specify if the Redis connection should use SSL or not.
2024-10-11 21:41:19 -03:00

21 lines
530 B
Python

import socketio # type: ignore
from config import REDIS_URL
class SocketHandler:
def __init__(self) -> None:
self.socket_server = socketio.AsyncServer(
cors_allowed_origins="*",
async_mode="asgi",
logger=False,
engineio_logger=False,
client_manager=socketio.AsyncRedisManager(str(REDIS_URL)),
)
self.socket_app = socketio.ASGIApp(
self.socket_server, socketio_path="/ws/socket.io"
)
socket_handler = SocketHandler()