2025-06-09 17:53:19 +08:00

33 lines
1.1 KiB
Python

# backend/run.py
import os
from myapp import create_app # Import the factory function
# Determine the configuration to use (e.g., from environment variable)
# Default to 'development' if FLASK_CONFIG is not set
config_name = os.environ.get('FLASK_CONFIG', 'development')
# Create the Flask app instance using the factory
app = create_app(config_name)
# Run the development server
if __name__ == "__main__":
# Get host and port from environment variables or use defaults
host = os.environ.get('FLASK_RUN_HOST', '0.0.0.0')
try:
port = int(os.environ.get('FLASK_RUN_PORT', '5000'))
except ValueError:
port = 5000
# Use Flask's built-in server for development.
# Debug mode should be controlled by the configuration loaded in create_app.
# app.run() will use app.config['DEBUG'] automatically.
print(f"Starting Flask server on {host}:{port} with config '{config_name}'...")
app.run(host=host, port=port)
# For production, you would typically use a WSGI server like Gunicorn or uWSGI:
# Example: gunicorn -w 4 -b 0.0.0.0:5000 "run:create_app('production')"