46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
# Piano Practice Plan System - Entry Point
|
|
|
|
import os
|
|
import sys
|
|
import pathlib
|
|
|
|
# 修复Windows控制台编码
|
|
if sys.platform == "win32":
|
|
import io
|
|
sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding="utf-8")
|
|
|
|
# 修复工作目录 - 确保项目根目录正确
|
|
PROJECT_ROOT = pathlib.Path(__file__).resolve().parent
|
|
sys.path.insert(0, str(PROJECT_ROOT))
|
|
os.chdir(PROJECT_ROOT)
|
|
|
|
print(f"[INFO] Project root: {PROJECT_ROOT}")
|
|
print(f"[INFO] Working directory: {os.getcwd()}")
|
|
|
|
from app import create_app
|
|
|
|
app = create_app()
|
|
|
|
if __name__ == "__main__":
|
|
is_prod = os.environ.get("FLASK_ENV") == "production"
|
|
print("=" * 50)
|
|
print("Piano Practice Plan System")
|
|
print("=" * 50)
|
|
print("Access: http://127.0.0.1:5001")
|
|
print(f"Debug: {not is_prod}")
|
|
print("=" * 50)
|
|
if is_prod:
|
|
print("Using gunicorn")
|
|
import gunicorn.app.base
|
|
class Application(gunicorn.app.base.Application):
|
|
def init(self, parser, opts, args):
|
|
self.cfg.set('bind', '0.0.0.0:5001')
|
|
self.cfg.set('workers', 1)
|
|
self.cfg.set('worker_class', 'sync')
|
|
self.cfg.set('timeout', 60)
|
|
def load(self):
|
|
return app
|
|
Application().run()
|
|
else:
|
|
app.run(host="0.0.0.0", port=5001, debug=True, use_reloader=False)
|