Преглед на файлове

修正前端展示界面

zkn преди 1 месец
родител
ревизия
9193534b43
променени са 3 файла, в които са добавени 67 реда и са изтрити 9 реда
  1. 31 4
      build_release.sh
  2. 31 4
      shudao-chat-py/build_release.sh
  3. 5 1
      shudao-chat-py/main.py

+ 31 - 4
build_release.sh

@@ -9,10 +9,37 @@ echo "========================================================"
 echo ""
 
 # 设置路径变量
-ROOT_DIR=$(pwd)
-PARENT_DIR=$(dirname "$ROOT_DIR")
-FRONTEND_DIR="$PARENT_DIR/shudao-main/shudao-vue-frontend"
-BACKEND_DIR="$ROOT_DIR"
+# Paths (robust to where you run the script from)
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Backend dir: contains main.py + requirements.txt
+if [ -f "$SCRIPT_DIR/main.py" ]; then
+    BACKEND_DIR="$SCRIPT_DIR"
+    PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
+elif [ -f "$SCRIPT_DIR/shudao-chat-py/main.py" ]; then
+    PROJECT_ROOT="$SCRIPT_DIR"
+    BACKEND_DIR="$PROJECT_ROOT/shudao-chat-py"
+elif [ -f "$PWD/main.py" ]; then
+    BACKEND_DIR="$PWD"
+    PROJECT_ROOT="$(cd "$PWD/.." && pwd)"
+else
+    echo "[ERROR] Cannot locate backend directory (main.py)."
+    echo "        Run this script from shudao-main/ or shudao-chat-py/."
+    exit 1
+fi
+
+# Frontend dir: contains package.json
+if [ -d "$PROJECT_ROOT/shudao-vue-frontend" ]; then
+    FRONTEND_DIR="$PROJECT_ROOT/shudao-vue-frontend"
+elif [ -d "$PROJECT_ROOT/shudao-main/shudao-vue-frontend" ]; then
+    # Backward compatibility for layouts like: /opt/www/{shudao-chat-py, shudao-main/shudao-vue-frontend}
+    FRONTEND_DIR="$PROJECT_ROOT/shudao-main/shudao-vue-frontend"
+else
+    echo "[ERROR] Cannot locate frontend directory (shudao-vue-frontend)."
+    exit 1
+fi
+
+ROOT_DIR="$BACKEND_DIR"
 DEPLOY_DIR="/opt/www/shudao-chat-py"
 SERVICE_NAME="shudao-chat-py"
 SERVICE_PORT=22001

+ 31 - 4
shudao-chat-py/build_release.sh

@@ -9,10 +9,37 @@ echo "========================================================"
 echo ""
 
 # 设置路径变量
-ROOT_DIR=$(pwd)
-PARENT_DIR=$(dirname "$ROOT_DIR")
-FRONTEND_DIR="$PARENT_DIR/shudao-main/shudao-vue-frontend"
-BACKEND_DIR="$ROOT_DIR"
+# Paths (robust to where you run the script from)
+SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
+
+# Backend dir: contains main.py + requirements.txt
+if [ -f "$SCRIPT_DIR/main.py" ]; then
+    BACKEND_DIR="$SCRIPT_DIR"
+    PROJECT_ROOT="$(cd "$SCRIPT_DIR/.." && pwd)"
+elif [ -f "$SCRIPT_DIR/shudao-chat-py/main.py" ]; then
+    PROJECT_ROOT="$SCRIPT_DIR"
+    BACKEND_DIR="$PROJECT_ROOT/shudao-chat-py"
+elif [ -f "$PWD/main.py" ]; then
+    BACKEND_DIR="$PWD"
+    PROJECT_ROOT="$(cd "$PWD/.." && pwd)"
+else
+    echo "[ERROR] Cannot locate backend directory (main.py)."
+    echo "        Run this script from shudao-main/ or shudao-chat-py/."
+    exit 1
+fi
+
+# Frontend dir: contains package.json
+if [ -d "$PROJECT_ROOT/shudao-vue-frontend" ]; then
+    FRONTEND_DIR="$PROJECT_ROOT/shudao-vue-frontend"
+elif [ -d "$PROJECT_ROOT/shudao-main/shudao-vue-frontend" ]; then
+    # Backward compatibility for layouts like: /opt/www/{shudao-chat-py, shudao-main/shudao-vue-frontend}
+    FRONTEND_DIR="$PROJECT_ROOT/shudao-main/shudao-vue-frontend"
+else
+    echo "[ERROR] Cannot locate frontend directory (shudao-vue-frontend)."
+    exit 1
+fi
+
+ROOT_DIR="$BACKEND_DIR"
 DEPLOY_DIR="/opt/www/shudao-chat-py"
 SERVICE_NAME="shudao-chat-py"
 SERVICE_PORT=22001

+ 5 - 1
shudao-chat-py/main.py

@@ -1,7 +1,7 @@
 from fastapi import FastAPI, Request
 from fastapi.staticfiles import StaticFiles
 from fastapi.middleware.cors import CORSMiddleware
-from fastapi.responses import HTMLResponse
+from fastapi.responses import HTMLResponse, FileResponse
 from utils.config import settings
 from utils.auth_middleware import auth_middleware
 from utils.logger import logger
@@ -126,6 +126,10 @@ app.mount("/assets", StaticFiles(directory="assets"), name="assets")
 @app.get("/", response_class=HTMLResponse)
 async def root():
     """根路径 - 欢迎页面"""
+    frontend_index = Path("views") / "index.html"
+    if frontend_index.is_file():
+        return FileResponse(frontend_index, media_type="text/html")
+
     html_content = """
     <!DOCTYPE html>
     <html lang="zh-CN">