更新 app.py:修正前端路徑指向 React
變更: - 前端路徑從 frontend/static/ 更新為 frontend-react/dist/ - 添加更詳細的錯誤提示(npm run build) - 添加註解說明推薦使用 start_dev.bat 進行開發 - 配合清理後的專案結構(已刪除舊 frontend 目錄) 🤖 Generated with Claude Code Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
20
app.py
20
app.py
@@ -43,19 +43,27 @@ class TimelineDesignerApp:
|
|||||||
Returns:
|
Returns:
|
||||||
前端 index.html 的絕對路徑
|
前端 index.html 的絕對路徑
|
||||||
"""
|
"""
|
||||||
# 開發模式:從專案目錄載入
|
# 開發模式:使用 React 開發伺服器
|
||||||
dev_path = Path(__file__).parent / "frontend" / "static" / "index.html"
|
# 注意:需要先執行 `npm run dev` 啟動 React 前端
|
||||||
if dev_path.exists():
|
# PyWebview 模式已不推薦使用,建議使用 start_dev.bat 啟動前後端分離模式
|
||||||
return str(dev_path.absolute())
|
|
||||||
|
# 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():
|
if bundle_path.exists():
|
||||||
return str(bundle_path.absolute())
|
return str(bundle_path.absolute())
|
||||||
|
|
||||||
# 找不到前端檔案
|
# 找不到前端檔案
|
||||||
logger.error("找不到前端 HTML 檔案")
|
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):
|
def start_api_server(self):
|
||||||
"""
|
"""
|
||||||
|
|||||||
Reference in New Issue
Block a user