Spaces:
Sleeping
Sleeping
| # main.py | |
| import os | |
| import sys | |
| # Make stdout/stderr UTF-8 so the app's Chinese log messages don't crash on | |
| # Windows consoles (default cp1252). No-op on Linux/Docker (already UTF-8). | |
| for _stream in (sys.stdout, sys.stderr): | |
| try: | |
| _stream.reconfigure(encoding="utf-8", errors="replace") | |
| except Exception: | |
| pass | |
| try: | |
| from app import create_app | |
| app = create_app() | |
| except Exception as e: | |
| import traceback | |
| _err_text = traceback.format_exc() | |
| print("✗ Fallback activated due to error:") | |
| print(_err_text) | |
| from flask import Flask | |
| app = Flask(__name__) | |
| def hello(): | |
| # Surface the real startup error in the browser to aid debugging. | |
| return ( | |
| "<h2>Startup failed (fallback mode)</h2><pre>" + _err_text + "</pre>", | |
| 500, | |
| {"Content-Type": "text/html; charset=utf-8"}, | |
| ) | |
| def healthz(): | |
| return "ok", 200 | |
| if __name__ == "__main__": | |
| port = int(os.environ.get("PORT", 10000)) | |
| app.run(host="0.0.0.0", port=port, debug=False) | |