From abd964d89a912b199e541df793671ff65933d342 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E5=B0=8F=E8=9A=82=E8=9A=81=E4=BA=91?= Date: Sat, 12 Sep 2026 19:51:59 +0800 Subject: [PATCH] =?UTF-8?q?=E7=AD=BE=E5=85=A5=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.example | 4 ++-- CLAUDE.md | 8 ++++---- Makefile | 2 +- config/app.py | 4 ++-- docker/Dockerfile | 8 ++++---- docker/docker-compose.yml | 4 ++-- gunicorn.conf.py | 2 +- scripts/health_check.py | 4 ++-- src/modules/job/scheduler_service.py | 2 +- ui/.env.development | 2 +- 10 files changed, 20 insertions(+), 20 deletions(-) diff --git a/.env.example b/.env.example index a017927..3627efb 100644 --- a/.env.example +++ b/.env.example @@ -17,11 +17,11 @@ FLASK_ENV=development # development / production FLASK_DEBUG=True # 生产环境必须为 False FLASK_USE_RELOADER=False FLASK_HOST=127.0.0.1 -FLASK_PORT=8021 +FLASK_PORT=8023 FLASK_SECRET_KEY=<必填,长度至少16字符,如生成随机串> FLASK_DEMO=False # True=演示模式,拦截写操作 # 站点域名(定时任务等内部 HTTP 调用使用) -# FLASK_SITE_DOMAIN=http://127.0.0.1:8021 +# FLASK_SITE_DOMAIN=http://127.0.0.1:8023 # 跨域白名单(多个用英文逗号分隔;配置后 CORS 允许携带凭证) CORS_ALLOWED_ORIGINS=http://localhost:8001 diff --git a/CLAUDE.md b/CLAUDE.md index 8bd9d81..d066863 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -18,7 +18,7 @@ DjangoAdmin Flask+EleVue is a separated frontend-backend admin framework. Backen # Install dependencies pip install -r requirements.txt -# Run dev server (default: 127.0.0.1:8021) +# Run dev server (default: 127.0.0.1:8023) python app.py # Database migrations (Flask-Migrate/Alembic) @@ -36,7 +36,7 @@ cd ui # Install dependencies (uses pnpm) pnpm install -# Run dev server (default: localhost:8001, proxies /api to backend :8021) +# Run dev server (default: localhost:8001, proxies /api to backend :8023) pnpm run dev # Build for production @@ -111,7 +111,7 @@ The framework uses an AOP-style transaction interceptor (`src/middleware/transac - Frontend response handler checks `code === 0` for success; `code=401` triggers re-login - **统一约定:所有响应(含认证/权限失败 401/403)返回 HTTP 200 + 业务 code**,不返回对应 HTTP 状态码——前端按 `code` 判断(401 重登、403 无权限)。若需按 HTTP 状态码防护(WAF/代理),应解析业务 code 而非 HTTP status - Permission strings follow pattern: `sys:module:action` (e.g., `sys:user:page`, `sys:role:add`) -- Frontend proxies `/api` prefix to backend via Vite dev server proxy (configured in `ui/.env.development` as `VITE_PROXY=[["/api","http://127.0.0.1:8021/"]]`) +- Frontend proxies `/api` prefix to backend via Vite dev server proxy (configured in `ui/.env.development` as `VITE_PROXY=[["/api","http://127.0.0.1:8023/"]]`) ### Naming Conventions @@ -137,7 +137,7 @@ The framework uses an AOP-style transaction interceptor (`src/middleware/transac ## Environment Configuration All config is in `.env` at project root. Key settings: -- `FLASK_HOST` / `FLASK_PORT` (default 127.0.0.1:8021) +- `FLASK_HOST` / `FLASK_PORT` (default 127.0.0.1:8023) - `FLASK_SECRET_KEY` — must be >= 16 chars or app refuses to start - `DB_*` — 数据库连接,**多库支持**(`config/database.py` 的 `_build_database_url()` 按 `DB_DRIVER` 构建 URL):`mysql`(默认)/`postgresql`/`mssql`/`sqlite`/`oracle`(oracledb 驱动,thin 模式无需 Oracle Client;`DB_DATABASE` 填 SERVICE_NAME)。切换只需改 `DB_DRIVER` + 账号,然后运行 `python scripts/setup_db.py`(`create_all` 建表 + 种子数据,幂等)。注意:`flask db migrate/upgrade`(方案 B)仍针对 MySQL,新建其它库请用 `scripts/setup_db.py` - **跨库数据迁移**:`python scripts/migrate_db.py --src-driver=mysql --src-host=127.0.0.1 --src-port=3306 --src-db=<源库名> --src-user=root --src-pass=<密码> --dst-driver=postgresql --dst-host=127.0.0.1 --dst-port=5432 --dst-db=<目标库名> --dst-user=postgres --dst-pass=<密码> --drop-target-first`。CLI 显式参数、不依赖 `.env`;源/目标均支持 `mysql/postgresql/mssql/sqlite/oracle`(别名 `postgres=postgresql`、`sqlserver=mssql`、`sqlite3=sqlite`),自动建目标库 + `create_all` 建表 + 逐表泵数据 + 按方言重置自增(PG setval / MSSQL CHECKIDENT / Oracle 补 sequence+触发器)+ 逐表行数校验;先加 `--dry-run` 干跑核对计划 diff --git a/Makefile b/Makefile index 07d5474..7843019 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ install-dev: ## 安装开发依赖(含生产依赖 + 测试/规范工 $(PIP) install -r requirements-dev.txt # ---- 运行 ---- -dev: ## 启动开发服务器(127.0.0.1:8021) +dev: ## 启动开发服务器(127.0.0.1:8023) $(PYTHON) app.py # ---- 代码质量 ---- diff --git a/config/app.py b/config/app.py index a96cd2f..4cdae6f 100644 --- a/config/app.py +++ b/config/app.py @@ -33,8 +33,8 @@ FLASK_SECRET_KEY = os.getenv('FLASK_SECRET_KEY', '') FLASK_HOST = os.getenv('FLASK_HOST', '127.0.0.1') # 应用运行端口 - 确保端口未被其他服务占用 -# 常用端口:8021(开发)、80(HTTP)、443(HTTPS) -FLASK_PORT = int(os.getenv('FLASK_PORT', 8021)) +# 常用端口:8023(开发)、80(HTTP)、443(HTTPS) +FLASK_PORT = int(os.getenv('FLASK_PORT', 8023)) # 站点域名 - 用于定时任务、邮件模板、微信回调等场景构建完整URL # 自动根据 HOST 和 PORT 生成,生产环境建议手动配置为真实域名 diff --git a/docker/Dockerfile b/docker/Dockerfile index b858a68..b68d67c 100644 --- a/docker/Dockerfile +++ b/docker/Dockerfile @@ -153,13 +153,13 @@ USER flask_user # 定义健康检查命令(需应用提供 /health 端点) # 生产环境建议使用 curl 或 wget 检查 HEALTHCHECK --interval=30s --timeout=5s --retries=3 --start-period=10s \ - CMD curl -f http://localhost:8021/health || exit 1 + CMD curl -f http://localhost:8023/health || exit 1 # ---------------------------------------------------------------------------- # 容器暴露端口声明 # ---------------------------------------------------------------------------- # 声明应用监听端口(仅用于文档说明,实际映射在 docker-compose 中配置) -EXPOSE 8021 +EXPOSE 8023 # ---------------------------------------------------------------------------- # 容器启动命令 @@ -184,7 +184,7 @@ CMD ["gunicorn", "-c", "gunicorn.conf.py", "src.wsgi:app"] # docker history flask_elevue:latest # # 5. 运行容器测试: -# docker run -d -p 8021:8021 flask_elevue:latest +# docker run -d -p 8023:8023 flask_elevue:latest # # 6. 进入容器调试: -# docker run -it --entrypoint /bin/bash flask_elevue:latest \ No newline at end of file +# docker run -it --entrypoint /bin/bash flask_elevue:latest diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index dae74aa..b62dc96 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -61,7 +61,7 @@ services: # 格式:宿主机端口:容器端口 # 注意:host 模式下此配置无效,保留是为了模式切换时生效 ports: - - 8021:8021 + - 8023:8023 # ------------------------------------------------------------------------ # 存储配置(数据持久化) @@ -165,4 +165,4 @@ services: # □ 定期更新基础镜像(python:3.x-slim 或 alpine)修复安全漏洞 # □ 使用镜像扫描工具(Trivy/Clair)检测漏洞 # □ 资源限制值根据实际压测结果动态调整 -# ============================================================================ \ No newline at end of file +# ============================================================================ diff --git a/gunicorn.conf.py b/gunicorn.conf.py index 023798c..5636a1c 100644 --- a/gunicorn.conf.py +++ b/gunicorn.conf.py @@ -18,7 +18,7 @@ import multiprocessing # ============================================================ # 监听地址(0.0.0.0 表示所有网卡,Docker 容器内必须) -bind = os.getenv('GUNICORN_BIND', f'0.0.0.0:{os.getenv("FLASK_PORT", "8021")}') +bind = os.getenv('GUNICORN_BIND', f'0.0.0.0:{os.getenv("FLASK_PORT", "8023")}') # ============================================================ # Worker 配置 diff --git a/scripts/health_check.py b/scripts/health_check.py index 95dc868..0366214 100644 --- a/scripts/health_check.py +++ b/scripts/health_check.py @@ -6,7 +6,7 @@ 验证应用可构建、健康端点可访问。 用法: - python scripts/health_check.py [--host 127.0.0.1] [--port 8021] + python scripts/health_check.py [--host 127.0.0.1] [--port 8023] """ import os @@ -45,7 +45,7 @@ def check_health_endpoint(host: str, port: int) -> bool: def main(): host = "127.0.0.1" - port = 8021 + port = 8023 args = sys.argv[1:] for i, a in enumerate(args): if a == "--host" and i + 1 < len(args): diff --git a/src/modules/job/scheduler_service.py b/src/modules/job/scheduler_service.py index 32fb12b..a203114 100644 --- a/src/modules/job/scheduler_service.py +++ b/src/modules/job/scheduler_service.py @@ -165,7 +165,7 @@ def build_full_url(url: str) -> str: Examples: >>> build_full_url('/job/sendSms') - 'http://127.0.0.1:8021/job/sendSms' + 'http://127.0.0.1:8023/job/sendSms' >>> build_full_url('https://api.example.com/test') 'https://api.example.com/test' """ diff --git a/ui/.env.development b/ui/.env.development index 5012322..e8a7c23 100644 --- a/ui/.env.development +++ b/ui/.env.development @@ -11,7 +11,7 @@ VITE_USE_MOCK = false VITE_DROP_CONSOLE = true # 跨域代理,可以配置多个,请注意不要换行 -VITE_PROXY=[["/api","http://127.0.0.1:8021/api/v1"]] +VITE_PROXY=[["/api","http://127.0.0.1:8023/api/v1"]] # API 接口地址 VITE_GLOB_API_URL =