|
4 | 4 | import os |
5 | 5 | import sys |
6 | 6 |
|
7 | | -# Add the current directory to Python path |
8 | | -sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) |
| 7 | +# Add the current directory to Python path FIRST |
| 8 | +current_dir = os.path.dirname(os.path.abspath(__file__)) |
| 9 | +sys.path.insert(0, current_dir) |
9 | 10 |
|
10 | | -# Import after path setup to avoid linting issues |
11 | | -from src.app import create_app # noqa: E402 |
12 | | -from src.models import db # noqa: E402 |
| 11 | +print(f"Python path: {sys.path}") |
| 12 | +print(f"Current directory: {current_dir}") |
| 13 | +print(f"Files in current directory: {os.listdir(current_dir)}") |
13 | 14 |
|
14 | | -# Create Flask app |
15 | | -app = create_app() |
16 | | - |
17 | | -# Initialize database tables |
18 | | -with app.app_context(): |
19 | | - db.create_all() |
| 15 | +try: |
| 16 | + # Import after path setup to avoid linting issues |
| 17 | + from src.app import create_app # noqa: E402 |
| 18 | + from src.models import db # noqa: E402 |
| 19 | + print("Imports successful") |
| 20 | + |
| 21 | + # Create Flask app (this happens when Gunicorn imports this file) |
| 22 | + app = create_app() |
| 23 | + print("Flask app created successfully") |
| 24 | + |
| 25 | + # Initialize database tables (this needs to happen when the module loads) |
| 26 | + try: |
| 27 | + with app.app_context(): |
| 28 | + db.create_all() |
| 29 | + print("Database tables created successfully") |
| 30 | + except Exception as e: |
| 31 | + print(f"Database initialization error: {e}") |
| 32 | + |
| 33 | +except ImportError as e: |
| 34 | + print(f"Import error: {e}") |
| 35 | + print(f"sys.path: {sys.path}") |
| 36 | + # Fallback: create a simple Flask app |
| 37 | + from flask import Flask |
| 38 | + app = Flask(__name__) |
| 39 | + |
| 40 | + @app.route('/') |
| 41 | + def hello(): |
| 42 | + return "Hello, deployment debugging!" |
| 43 | + |
| 44 | + @app.route('/health') |
| 45 | + def health(): |
| 46 | + return {"status": "healthy", "message": "Basic Flask app running"} |
20 | 47 |
|
21 | 48 | if __name__ == '__main__': |
22 | | - # Get port from environment variable (Azure sets this as WEBSITES_PORT) |
| 49 | + # This only runs when executed directly, not through Gunicorn |
23 | 50 | port = int(os.environ.get('WEBSITES_PORT', os.environ.get('PORT', 8000))) |
24 | 51 | app.run(debug=False, host='0.0.0.0', port=port) |
0 commit comments