### 本地开发环境基础设施 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md 使用 Docker 启动开发所需的 MySQL 和 Redis 服务。 ```bash docker compose up -d mysql redis ``` -------------------------------- ### 本地源码 Docker 构建 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md 使用 build.sh 脚本进行容器构建与管理。 ```bash bash build.sh rebuild ``` ```bash bash build_frontend.sh # 重建前端 bash build_backend_web.sh # 重建 Backend-Web bash build_websocket.sh # 重建 WebSocket bash build_scheduler.sh # 重建 Scheduler ``` -------------------------------- ### 启动后端服务 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md 分别启动 Backend-Web、WebSocket 和 Scheduler 服务。 ```bash # Backend-Web 服务 cd backend-web python -m venv .venv # Windows: .venv\Scripts\activate # Linux/macOS: source .venv/bin/activate pip install -e . python -m playwright install chromium python -m patchright install chromium python main.py ``` ```bash # WebSocket 服务 cd websocket python -m venv .venv # Windows: .venv\Scripts\activate # Linux/macOS: source .venv/bin/activate pip install -e . python -m playwright install chromium python -m patchright install chromium python main.py ``` ```bash # Scheduler 服务 cd scheduler python -m venv .venv # Windows: .venv\Scripts\activate # Linux/macOS: source .venv/bin/activate pip install -e . python -m playwright install chromium python main.py ``` -------------------------------- ### 远程 MySQL / Redis 部署 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md 使用外部数据库服务进行部署,需配置 .env.remote 文件。 ```bash # 1) 首次运行:自动生成 .env.remote 后退出,提示填写远程连接信息 curl -fsSL https://xy-update.zhinianboke.com/deploy_remote.sh | sed 's/\r$//' | bash # 2) 编辑 .env.remote,填写真实的远程地址(勿填 localhost) # MYSQL_HOST / REDIS_HOST 等 vim .env.remote # 3) 再次运行:校验配置 → 自动生成 docker-compose.remote.yml → 拉取镜像 → 启动 curl -fsSL https://xy-update.zhinianboke.com/deploy_remote.sh | sed 's/\r$//' | bash ``` -------------------------------- ### 服务器一键部署与更新 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md 使用官方脚本进行自动化部署或版本更新。 ```bash curl -fsSL https://xy-update.zhinianboke.com/deploy.sh | sed 's/\r$//' | bash ``` ```bash curl -fsSL https://xy-update.zhinianboke.com/update.sh | sed 's/\r$//' | bash ``` -------------------------------- ### 启动返佣子系统 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md 启动返佣功能的后端与前端服务。 ```bash # 返佣后端 cd promotion/backend pip install -e . python main.py # 返佣前端 cd promotion/frontend npm install npm run dev ``` -------------------------------- ### 启动前端服务 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md 安装依赖并启动前端开发服务器。 ```bash cd frontend npm install npm run dev ``` -------------------------------- ### 初始化主题模式 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/frontend/index.html 在页面加载时自动检测并应用深色模式。依赖于localStorage中的theme设置或系统偏好设置。 ```javascript (function() { var theme = localStorage.getItem('theme'); var prefersDark = window.matchMedia('(prefers-color-scheme: dark)').matches; if (theme === 'dark' || (!theme && prefersDark)) { document.documentElement.classList.add('dark'); } })(); ``` -------------------------------- ### 开发环境配置示例 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md 主系统开发所需的 .env 环境变量配置。 ```env ENVIRONMENT=development MYSQL_HOST=127.0.0.1 MYSQL_PORT=3306 MYSQL_USER=root MYSQL_PASSWORD=root MYSQL_DATABASE=xianyu_data REDIS_HOST=127.0.0.1 REDIS_PORT=6379 REDIS_PASSWORD= REDIS_DB=0 CORS_ORIGINS=* BACKEND_WEB_PORT=8089 WEBSOCKET_PORT=8090 SCHEDULER_PORT=8091 WEBSOCKET_SERVICE_URL=http://127.0.0.1:8090 SCHEDULER_SERVICE_URL=http://127.0.0.1:8091 BACKEND_WEB_SERVICE_URL=http://127.0.0.1:8089 STATIC_DIR=static TZ=Asia/Shanghai ``` -------------------------------- ### Initialize Dark Mode Theme Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/promotion/frontend/index.html This script checks local storage or system preferences to apply the dark mode class to the document element, preventing visual flickering on page load. ```javascript (function() { const theme = localStorage.getItem('theme') if (theme === 'dark' || (!theme && window.matchMedia('(prefers-color-scheme: dark)').matches)) { document.documentElement.classList.add('dark') } })() ``` -------------------------------- ### 克隆仓库部署 Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md 手动克隆仓库并执行部署脚本。 ```bash git clone https://github.com/zhinianboke/xianyu-auto-reply.git cd xianyu-auto-reply bash deploy.sh ``` ```bash bash update.sh ``` -------------------------------- ### Standard Backend JSON Response Format Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md The backend uses a unified response wrapper where business exceptions are also returned with an HTTP 200 status code. ```json { "success": true, "code": 200, "message": "操作成功", "data": {} } ``` -------------------------------- ### Fix Bash Script Line Ending Issues Source: https://github.com/zhinianboke/xianyu-auto-reply/blob/main/README.md Resolves 'bad interpreter' errors caused by Windows-style CRLF line endings in shell scripts on Linux systems. ```bash # 方法一:用 sed 去除 \r 后执行 sed -i 's/\r$//' deploy.sh bash deploy.sh # 方法二:通过管道执行(推荐远程脚本使用) curl -fsSL https://xy-update.zhinianboke.com/deploy.sh | sed 's/\r$//' | bash ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.