feat(socketio): integrate SocketIO service for real-time communication and emit credits change events
This commit is contained in:
@@ -4,13 +4,15 @@ from datetime import timedelta
|
||||
from flask import Flask
|
||||
from flask_cors import CORS
|
||||
from flask_jwt_extended import JWTManager
|
||||
from flask_socketio import SocketIO
|
||||
|
||||
from app.database import init_db
|
||||
from app.services.auth_service import AuthService
|
||||
from app.services.scheduler_service import scheduler_service
|
||||
|
||||
# Global auth service instance
|
||||
# Global service instances
|
||||
auth_service = AuthService()
|
||||
socketio = SocketIO()
|
||||
|
||||
|
||||
def create_app():
|
||||
@@ -35,7 +37,7 @@ def create_app():
|
||||
app.config["JWT_TOKEN_LOCATION"] = ["cookies"]
|
||||
app.config["JWT_COOKIE_SECURE"] = False # Set to True in production
|
||||
app.config["JWT_COOKIE_CSRF_PROTECT"] = False
|
||||
app.config["JWT_ACCESS_COOKIE_PATH"] = "/api/"
|
||||
app.config["JWT_ACCESS_COOKIE_PATH"] = "/" # Allow access to all paths including SocketIO
|
||||
app.config["JWT_REFRESH_COOKIE_PATH"] = "/api/auth/refresh"
|
||||
|
||||
# Initialize CORS
|
||||
@@ -47,6 +49,13 @@ def create_app():
|
||||
methods=["GET", "POST", "PATCH", "PUT", "DELETE", "OPTIONS"],
|
||||
)
|
||||
|
||||
# Initialize SocketIO
|
||||
socketio.init_app(
|
||||
app,
|
||||
cors_allowed_origins="http://localhost:3000",
|
||||
cors_credentials=True,
|
||||
)
|
||||
|
||||
# Initialize JWT manager
|
||||
jwt = JWTManager(app)
|
||||
|
||||
@@ -62,6 +71,9 @@ def create_app():
|
||||
# Initialize authentication service with app
|
||||
auth_service.init_app(app)
|
||||
|
||||
# Initialize SocketIO service (import after socketio is initialized)
|
||||
from app.services.socketio_service import socketio_service # noqa: F401
|
||||
|
||||
# Initialize scheduler service with app
|
||||
scheduler_service.app = app
|
||||
|
||||
|
||||
Reference in New Issue
Block a user