From ad9ba59fdf48f7de8c2376e5ae7f9aae85d6b451 Mon Sep 17 00:00:00 2001 From: beabigegg Date: Thu, 6 Nov 2025 11:44:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=20app.py=EF=BC=9A=E4=BF=AE?= =?UTF-8?q?=E6=AD=A3=E5=89=8D=E7=AB=AF=E8=B7=AF=E5=BE=91=E6=8C=87=E5=90=91?= =?UTF-8?q?=20React?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 變更: - 前端路徑從 frontend/static/ 更新為 frontend-react/dist/ - 添加更詳細的錯誤提示(npm run build) - 添加註解說明推薦使用 start_dev.bat 進行開發 - 配合清理後的專案結構(已刪除舊 frontend 目錄) 🤖 Generated with Claude Code Co-Authored-By: Claude --- app.py | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/app.py b/app.py index 96b9c2c..f9cc8a2 100644 --- a/app.py +++ b/app.py @@ -43,19 +43,27 @@ class TimelineDesignerApp: Returns: 前端 index.html 的絕對路徑 """ - # 開發模式:從專案目錄載入 - dev_path = Path(__file__).parent / "frontend" / "static" / "index.html" - if dev_path.exists(): - return str(dev_path.absolute()) + # 開發模式:使用 React 開發伺服器 + # 注意:需要先執行 `npm run dev` 啟動 React 前端 + # PyWebview 模式已不推薦使用,建議使用 start_dev.bat 啟動前後端分離模式 + + # React 打包後的前端檔案 + react_dist_path = Path(__file__).parent / "frontend-react" / "dist" / "index.html" + if react_dist_path.exists(): + logger.info("使用 React 打包後的前端") + return str(react_dist_path.absolute()) # 打包模式:從執行檔旁邊載入 - bundle_path = Path(sys.executable).parent / "frontend" / "static" / "index.html" + bundle_path = Path(sys.executable).parent / "frontend-react" / "dist" / "index.html" if bundle_path.exists(): return str(bundle_path.absolute()) # 找不到前端檔案 logger.error("找不到前端 HTML 檔案") - raise FileNotFoundError("Frontend index.html not found") + logger.error("請執行以下命令建置前端:") + logger.error(" cd frontend-react") + logger.error(" npm run build") + raise FileNotFoundError("Frontend index.html not found. Please run 'npm run build' in frontend-react/") def start_api_server(self): """