diff --git a/.env.example b/.env.example index 3627efb..a017927 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=8023 +FLASK_PORT=8021 FLASK_SECRET_KEY=<必填,长度至少16字符,如生成随机串> FLASK_DEMO=False # True=演示模式,拦截写操作 # 站点域名(定时任务等内部 HTTP 调用使用) -# FLASK_SITE_DOMAIN=http://127.0.0.1:8023 +# FLASK_SITE_DOMAIN=http://127.0.0.1:8021 # 跨域白名单(多个用英文逗号分隔;配置后 CORS 允许携带凭证) CORS_ALLOWED_ORIGINS=http://localhost:8001 diff --git a/.jenkins/Dockerfile b/.jenkins/Dockerfile index d2c5b5e..d40c686 100644 --- a/.jenkins/Dockerfile +++ b/.jenkins/Dockerfile @@ -139,4 +139,4 @@ EXPOSE ${PORT} # CMD ["sh","-c","uwsgi --http 0.0.0.0:${PORT} \ # --module 你的项目名.wsgi:application \ # --processes 4 --threads 2"] -CMD ["sh", "-c", "python3 app.py runserver 0.0.0.0:${PORT} --noreload"] +CMD ["sh", "-c", "gunicorn -c gunicorn.conf.py src.wsgi:app -b 0.0.0.0:${PORT}"] diff --git a/CLAUDE.md b/CLAUDE.md index d066863..8bd9d81 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:8023) +# Run dev server (default: 127.0.0.1:8021) 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 :8023) +# Run dev server (default: localhost:8001, proxies /api to backend :8021) 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:8023/"]]`) +- 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/"]]`) ### 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:8023) +- `FLASK_HOST` / `FLASK_PORT` (default 127.0.0.1:8021) - `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 7843019..07d5474 100644 --- a/Makefile +++ b/Makefile @@ -27,7 +27,7 @@ install-dev: ## 安装开发依赖(含生产依赖 + 测试/规范工 $(PIP) install -r requirements-dev.txt # ---- 运行 ---- -dev: ## 启动开发服务器(127.0.0.1:8023) +dev: ## 启动开发服务器(127.0.0.1:8021) $(PYTHON) app.py # ---- 代码质量 ---- diff --git a/config/app.py b/config/app.py index 4cdae6f..a96cd2f 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') # 应用运行端口 - 确保端口未被其他服务占用 -# 常用端口:8023(开发)、80(HTTP)、443(HTTPS) -FLASK_PORT = int(os.getenv('FLASK_PORT', 8023)) +# 常用端口:8021(开发)、80(HTTP)、443(HTTPS) +FLASK_PORT = int(os.getenv('FLASK_PORT', 8021)) # 站点域名 - 用于定时任务、邮件模板、微信回调等场景构建完整URL # 自动根据 HOST 和 PORT 生成,生产环境建议手动配置为真实域名 diff --git a/docker/Dockerfile b/docker/Dockerfile index b68d67c..a176b43 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:8023/health || exit 1 + CMD curl -f http://localhost:8021/health || exit 1 # ---------------------------------------------------------------------------- # 容器暴露端口声明 # ---------------------------------------------------------------------------- # 声明应用监听端口(仅用于文档说明,实际映射在 docker-compose 中配置) -EXPOSE 8023 +EXPOSE 8021 # ---------------------------------------------------------------------------- # 容器启动命令 @@ -184,7 +184,7 @@ CMD ["gunicorn", "-c", "gunicorn.conf.py", "src.wsgi:app"] # docker history flask_elevue:latest # # 5. 运行容器测试: -# docker run -d -p 8023:8023 flask_elevue:latest +# docker run -d -p 8021:8021 flask_elevue:latest # # 6. 进入容器调试: # docker run -it --entrypoint /bin/bash flask_elevue:latest diff --git a/docker/docker-compose.yml b/docker/docker-compose.yml index b62dc96..476a0b6 100644 --- a/docker/docker-compose.yml +++ b/docker/docker-compose.yml @@ -61,7 +61,7 @@ services: # 格式:宿主机端口:容器端口 # 注意:host 模式下此配置无效,保留是为了模式切换时生效 ports: - - 8023:8023 + - 8021:8021 # ------------------------------------------------------------------------ # 存储配置(数据持久化) diff --git a/gunicorn.conf.py b/gunicorn.conf.py index 5636a1c..023798c 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", "8023")}') +bind = os.getenv('GUNICORN_BIND', f'0.0.0.0:{os.getenv("FLASK_PORT", "8021")}') # ============================================================ # Worker 配置 diff --git a/scripts/health_check.py b/scripts/health_check.py index 0366214..95dc868 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 8023] + python scripts/health_check.py [--host 127.0.0.1] [--port 8021] """ import os @@ -45,7 +45,7 @@ def check_health_endpoint(host: str, port: int) -> bool: def main(): host = "127.0.0.1" - port = 8023 + port = 8021 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 a203114..32fb12b 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:8023/job/sendSms' + 'http://127.0.0.1:8021/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 e8a7c23..5012322 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:8023/api/v1"]] +VITE_PROXY=[["/api","http://127.0.0.1:8021/api/v1"]] # API 接口地址 VITE_GLOB_API_URL =