Files
capitalism-eats-the-world/app/__init__.py
Markus Busche 97e9e18ee5 Enhanced: Comprehensive production debugging and Nginx proxy support
Debugging Tools:
- Added /debug endpoint to verify deployment and test distribution functionality
- Added browser console test function: testDistributionChart()
- Enhanced SocketIO settings with better transport priorities
- Added comprehensive error tracking and status reporting

Nginx Configuration:
- Created NGINX_CONFIG.md with complete proxy setup guide
- Improved WebSocket transport settings and timeouts
- Better ping/pong settings for connection stability

Production Compatibility:
- Optimized SocketIO for proxy environments
- Enhanced fallback mechanisms
- Production-ready logging and error handling

This should resolve proxy-related issues and provide clear diagnostic tools.
2025-08-24 18:53:09 +00:00

65 lines
1.7 KiB
Python

"""
Flask Application Factory
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 with enhanced proxy support
socketio = SocketIO(
cors_allowed_origins="*",
async_mode='threading',
logger=False, # Disable to avoid log spam in production
engineio_logger=False,
# Transport order: try websocket first, then polling
transports=['websocket', 'polling'],
# Ping settings for better connection detection
ping_timeout=60,
ping_interval=25
)
# Global simulation manager instance
simulation_manager = SimulationManager()
def create_app(config_name=None):
"""
Create and configure the Flask application.
Args:
config_name: Configuration profile to use
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 with proxy-friendly settings
socketio.init_app(
app,
async_mode='threading',
cors_allowed_origins="*",
allow_upgrades=True,
transports=['websocket', 'polling'],
ping_timeout=60,
ping_interval=25
)
# Register blueprints
from .routes.main import main_bp
from .routes.api import api_bp
app.register_blueprint(main_bp)
app.register_blueprint(api_bp, url_prefix='/api')
return app