Fix: Wealth Distribution Histogram behind Nginx proxy

Production Environment Fixes:
- Enhanced SocketIO configuration for proxy compatibility
- Added fallback polling mechanism when WebSocket fails
- Fixed environment configuration (FLASK_ENV vs FLASK_CONFIG)
- Added production-friendly debug logging for distribution chart
- Improved connection status monitoring and error handling

Proxy-Specific Improvements:
- Enhanced CORS and transport settings for SocketIO
- Fallback to HTTP polling when WebSocket connections fail
- Better error handling and retry mechanisms
- Debug logging that works in production mode

This should resolve the wealth distribution histogram issue
when running behind Nginx proxy in Docker containers.
This commit is contained in:
2025-08-24 18:45:55 +00:00
parent 0fbee684f4
commit 6f94b1bd04
3 changed files with 215 additions and 65 deletions

View File

@@ -5,19 +5,25 @@ Creates and configures the Flask application with SocketIO support for real-time
updates of the Markov economics simulation.
"""
import os
from flask import Flask
from flask_socketio import SocketIO
from config import config
from app.models import SimulationManager
# Initialize SocketIO
socketio = SocketIO(cors_allowed_origins="*")
# Initialize SocketIO with enhanced proxy support
socketio = SocketIO(
cors_allowed_origins="*",
async_mode='threading',
logger=True,
engineio_logger=True
)
# Global simulation manager instance
simulation_manager = SimulationManager()
def create_app(config_name='development'):
def create_app(config_name=None):
"""
Create and configure the Flask application.
@@ -27,11 +33,20 @@ def create_app(config_name='development'):
Returns:
Configured Flask application instance
"""
if config_name is None:
config_name = os.getenv('FLASK_CONFIG', os.getenv('FLASK_ENV', 'development'))
app = Flask(__name__)
app.config.from_object(config[config_name])
# Initialize extensions
socketio.init_app(app, async_mode='threading')
# Initialize extensions with proxy-friendly settings
socketio.init_app(
app,
async_mode='threading',
cors_allowed_origins="*",
allow_upgrades=True,
transports=['websocket', 'polling']
)
# Register blueprints
from .routes.main import main_bp