Bläddra i källkod

-dev:完善前端后端,更新检查接口

LuoChinWen 4 veckor sedan
förälder
incheckning
ec5db0d002
4 ändrade filer med 169 tillägg och 4 borttagningar
  1. 35 2
      backend/main.py
  2. 2 2
      deploy.sh
  3. 65 0
      lq_label.conf
  4. 67 0
      sub_system_server.conf

+ 35 - 2
backend/main.py

@@ -65,8 +65,41 @@ async def root():
 
 @app.get("/health")
 async def health_check():
-    """Health check endpoint"""
-    return {"status": "healthy"}
+    """
+    健康检查接口
+    检查服务状态和数据库连接
+    """
+    import time
+    from database import get_db_connection, db_config
+    
+    start_time = time.time()
+    health_status = {
+        "status": "healthy",
+        "version": "1.0.0",
+        "checks": {}
+    }
+    
+    # 检查数据库连接
+    try:
+        with get_db_connection() as conn:
+            cursor = conn.cursor()
+            cursor.execute("SELECT 1")
+            cursor.fetchone()
+        health_status["checks"]["database"] = {
+            "status": "healthy",
+            "type": db_config.db_type
+        }
+    except Exception as e:
+        health_status["status"] = "unhealthy"
+        health_status["checks"]["database"] = {
+            "status": "unhealthy",
+            "error": str(e)
+        }
+    
+    # 响应时间
+    health_status["response_time_ms"] = round((time.time() - start_time) * 1000, 2)
+    
+    return health_status
 
 
 if __name__ == "__main__":

+ 2 - 2
deploy.sh

@@ -13,7 +13,7 @@ YELLOW='\033[1;33m'
 NC='\033[0m'
 
 # 配置变量(根据实际情况修改)
-FRONTEND_DEPLOY_DIR="/var/www/lq_label"  # 前端部署目录(Nginx root)
+FRONTEND_DEPLOY_DIR="/home/lq/nginx/html_app/lq_label"  # 前端部署目录(Nginx root)
 GIT_BRANCH="main"                         # Git 分支
 
 echo -e "${GREEN}============================================${NC}"
@@ -165,7 +165,7 @@ echo -e "${GREEN}============================================${NC}"
 echo -e "${GREEN}  部署完成!${NC}"
 echo -e "${GREEN}============================================${NC}"
 echo
-echo "前端地址: http://localhost (根据 Nginx 配置)"
+echo "前端地址: http://localhost:9101"
 echo "后端地址: http://localhost:8003"
 echo "API 文档: http://localhost:8003/docs"
 echo

+ 65 - 0
lq_label.conf

@@ -0,0 +1,65 @@
+server {
+    listen 9003;
+    server_name _;
+    root /home/lq/nginx/html_app/lq_label;
+    index index.html index.htm;
+
+    # 如果请求根目录,重定向到 index.html
+    location = / {
+        try_files $uri $uri/ /index.html;
+    }
+
+    # 静态资源缓存
+    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
+        expires 1y;
+        add_header Cache-Control "public, immutable";
+        access_log off;
+    }
+
+    # HTML 文件不缓存
+    location ~* \.html$ {
+        expires -1;
+        add_header Cache-Control "no-cache, no-store, must-revalidate";
+        add_header Pragma "no-cache";
+    }
+
+    # API 代理到后端
+    location /api/ {
+        proxy_pass http://127.0.0.1:8003/api/;
+        proxy_set_header Host $host;
+        proxy_set_header X-Real-IP $remote_addr;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header X-Forwarded-Proto $scheme;
+        proxy_connect_timeout 30s;
+        proxy_send_timeout 30s;
+        proxy_read_timeout 30s;
+    }
+
+    # OAuth 代理
+    location /auth/ {
+        proxy_pass http://127.0.0.1:8003/auth/;
+        proxy_set_header Host $host;
+        proxy_set_header X-Real-IP $remote_addr;
+        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+        proxy_set_header X-Forwarded-Proto $scheme;
+    }
+
+    # SPA 路由支持
+    location / {
+        try_files $uri $uri/ /index.html;
+    }
+
+    # 健康检查
+    location /health {
+        access_log off;
+        return 200 "healthy\n";
+        add_header Content-Type text/plain;
+    }
+
+    # 安全配置
+    location ~ /\. {
+        deny all;
+        access_log off;
+        log_not_found off;
+    }
+}

+ 67 - 0
sub_system_server.conf

@@ -0,0 +1,67 @@
+
+    server {
+        listen 9100;
+        server_name _;
+        root /usr/share/nginx/html_app/sub_system;
+        index index.html index.htm;
+
+       # 如果请求根目录,重定向到 index.html
+       location = / {
+          try_files $uri $uri/ /index.html;
+       }
+
+
+        # 静态资源缓存
+        location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg|woff|woff2|ttf|eot)$ {
+            expires 1y;
+            add_header Cache-Control "public, immutable";
+            access_log off;
+        }
+
+        # HTML 文件不缓存
+        location ~* \.html$ {
+            expires -1;
+            add_header Cache-Control "no-cache, no-store, must-revalidate";
+            add_header Pragma "no-cache";
+        }
+
+        # API 代理(可选,如果需要代理到后端)
+        location /api/ {
+            proxy_pass http://SubSystemServer:8100/api/;
+            proxy_set_header Host $host;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+            proxy_set_header X-Forwarded-Proto $scheme;
+            proxy_connect_timeout 30s;
+            proxy_send_timeout 30s;
+            proxy_read_timeout 30s;
+        }
+
+        # OAuth 代理
+        location /auth/ {
+            proxy_pass http://SubSystemServer:8100/auth/;
+            proxy_set_header Host $host;
+            proxy_set_header X-Real-IP $remote_addr;
+            proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
+            proxy_set_header X-Forwarded-Proto $scheme;
+        }
+
+        # SPA 路由支持
+        location / {
+            try_files $uri $uri/ /index.html;
+        }
+
+        # 健康检查
+        location /health {
+            access_log off;
+            return 200 "healthy\n";
+            add_header Content-Type text/plain;
+        }
+
+        # 安全配置
+        location ~ /\. {
+            deny all;
+            access_log off;
+            log_not_found off;
+        }
+    }