From cf6c2ca2632db0854a71b9af92ba15cfe6a8c21c Mon Sep 17 00:00:00 2001 From: errortopic Date: Wed, 18 Nov 2026 20:19:22 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=A0=B5=E4=BD=8F=20/api/dev/*=20?= =?UTF-8?q?=E5=85=AC=E7=BD=91=E5=85=A5=E5=8F=A3=EF=BC=8C=E4=BF=AE=E4=BC=9A?= =?UTF-8?q?=E8=AF=9D=E8=BF=87=E6=9C=9F=E6=97=B6=E9=97=B4=E4=B8=8E=E4=B8=8A?= =?UTF-8?q?=E4=BC=A0=E5=AD=A4=E5=84=BF=E6=96=87=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 安全(P0) - app.py: QINGLING_ENV=prod 时不注册 /api/dev/*(6 条)与短信登录(2 条), 请求落到 404;路由数 dev 57 / prod 49 - deploy: compose 默认 QINGLING_ENV=prod;Caddyfile 对 /api/dev/* 与 /api/auth/sms-* 再兜一层 404(就算环境变量被改回 dev,公网也打不到) - app.py: 生产环境不再把异常原文回给前端;CORS 生产默认不发 Access-Control-Allow-Origin(需要跨域用 QINGLING_CORS 配置) 正确性 - services: sessions.expires_at 从「创建时刻」改成「创建 + 7 天」(4 处: login / login_ticket / login_phone / _session_payload),并新增 purge_expired_sessions(),挂在 health 上顺手清理(这张表从没清过) - services: create_paper_from_image 在 OCR 抛异常、或退回演示题库时删掉 未入库的原图与擦除页,不再留孤儿文件;papers 表新增 image_path 并在 建卷时写入 - services: 新增 cleanup_uploads()/sweep_uploads(),按「文件名主干 = papers.id」清掉 90 天前没人引用的上传文件(每天最多扫一次) - app.py: 请求体按 Content-Length 限 16MB(直连 8000 时没有 Caddy 兜底), 坏 Content-Length 回 400 而不是 500 - app.py: paper_clean 按真实后缀回 Content-Type(TextIn 擦除结果是 .jpg, 以前一律当 png 发) 部署 - Dockerfile 安装 Pillow:没有它 img_w=img_h=0,「小图先拦一道」和 「图太小就不做 TextIn 擦除」在容器里会静默失效 - README/上线清单:补 prod 路由数与 /api/dev 验收项 验证 - python -m unittest(5 个模块)91 passed - 冒烟:prod 下 4 个 dev/sms 接口 404、routes=49、20MB 请求 413、 坏 Content-Length 400、expires_at=created+7d、health 清理过期会话、 清完旧令牌仍有效、papers.image_path 存在 - uploads 清理:孤儿文件删掉、被引用的原图与擦除页保留、新文件不动 --- .gitignore | 4 ++ backend/README.md | 8 ++- backend/app.py | 57 +++++++++++++++++---- backend/db.py | 3 +- backend/services.py | 101 +++++++++++++++++++++++++++++++++----- deploy/Caddyfile | 16 +++++- deploy/Dockerfile | 9 +++- deploy/README.md | 4 +- deploy/docker-compose.yml | 4 +- 9 files changed, 176 insertions(+), 30 deletions(-) diff --git a/.gitignore b/.gitignore index b8fbbbe..8c4686d 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,7 @@ data/textin.env .dsh-vision-router/ data/shot-profile/ + +# Óû§Éϴ«µľí×ÓÕÕƬ£º¾ø²»½ø²ֿâ +data/uploads/ + diff --git a/backend/README.md b/backend/README.md index 98e0ca4..c17c8d2 100644 --- a/backend/README.md +++ b/backend/README.md @@ -33,7 +33,8 @@ python -m backend.app --port 8000 ``` backend/ - app.py HTTP 层:路由 + 鉴权 + JSON/CORS + 接口文档页(57 条路由) + app.py HTTP 层:路由 + 鉴权 + JSON/CORS + 接口文档页(开发模式 57 条路由; + 生产模式 QINGLING_ENV=prod 不注册 /api/dev/* 与短信登录,共 49 条) services.py 业务用例:登录/同意/建档/拍卷/入库/今日队列/作答/讲清/周报/导出/提醒 scheduler.py 错题状态机 + 复习调度(1/3/7/15/30 天)+ 讲清 rubric judging.py 判题引擎(口算/竖式/听写/选择)+ 拒答 @@ -271,7 +272,10 @@ questions 入库(`options` 列存 JSON 数组,接口直接返回数组)→ - 已知限制:按次计费,余额不足时接口返回 `40003 余额不足`;对**低分辨率截图**(如 387×516 放大后) 会把字抹花——这种情况会直接跳过。 -## 五、接口(57 条) +## 五、接口(57 条,prod 下 49 条) + +> `/api/dev/*`(6 条)与 `/api/auth/sms-code`、`/api/auth/sms-login` 只在 `QINGLING_ENV` 不是 +> `prod` 时注册。生产环境里它们直接 404,连「存在」都不暴露。 | 方法 | 路径 | 鉴权 | 说明 | |---|---|---|---| diff --git a/backend/app.py b/backend/app.py index 69decfa..3793fa2 100644 --- a/backend/app.py +++ b/backend/app.py @@ -33,10 +33,27 @@ WORKBENCH = ROOT / "prototype" / "workbench" / "index.html" BRAND_DIR = ROOT / "brand" ROUTES: list[tuple[str, re.Pattern, object, str]] = [] +# 生产环境(QINGLING_ENV=prod)不注册这两组路由: +# /api/dev/* 能清库、能签年卡、能伪造扫码登录,只该在本地存在; +# /api/auth/sms-* 这一版没接短信服务商,验证码是随响应回显的, +# 线上等于「任意手机号都能直接注册并登录」。 +PROD = os.environ.get("QINGLING_ENV", "dev").strip().lower() in ("prod", "production") +DEV_ONLY_PREFIXES = ("/api/dev/", "/api/auth/sms-") +MAX_BODY = 16 * 1024 * 1024 # 与 Caddy 的 request_body max_size 对齐 +CORS_ORIGINS = [o.strip() for o in + (os.environ.get("QINGLING_CORS") or ("*" if not PROD else "")).split(",") + if o.strip()] + def route(method: str, pattern: str, auth: str = "parent"): - """auth: parent | child_ok | none""" + """auth: parent | child_ok | none + + 生产环境里 DEV_ONLY_PREFIXES 命中的路由直接不注册——请求会落到 404, + 而不是「注册了但返回 403」,这样连「这个接口存在」都不泄漏。 + """ def deco(fn): + if PROD and pattern.startswith(DEV_ONLY_PREFIXES): + return fn ROUTES.append((method, re.compile("^" + pattern + "$"), fn, auth)) return fn return deco @@ -69,8 +86,10 @@ class Ctx: @route("GET", "/api/health", auth="none") def health(ctx: Ctx, **kw): - try: # 顺手清理过期的删号申请(一次索引查询,很便宜) + try: # 顺手清理过期的删号申请与会话(各一次索引查询,很便宜) svc.purge_due(ctx.conn) + svc.purge_expired_sessions(ctx.conn) + svc.sweep_uploads(ctx.conn) # 上传目录按 90 天清,内部自己限每天一次 except Exception: pass return {"ok": True, "service": "qingling-primary", "version": "1.2.0", "time": dbm.now(), @@ -262,7 +281,8 @@ def paper_clean(ctx: Ctx, pid: str, **kw): fp = ROOT / row["clean_path"] if not fp.exists(): raise ApiError(404, "NO_CLEAN", "干净页文件不在了") - return ("png", fp.read_bytes()) + # TextIn 擦除出来的是 .jpg,别一律当 png 发 + return ("png" if fp.suffix.lower() == ".png" else "jpg", fp.read_bytes()) @route("GET", r"/api/papers/(?P[^/]+)", auth="parent") @@ -476,11 +496,16 @@ class App(BaseHTTPRequestHandler): self.send_response(status) self.send_header("Content-Type", ctype) self.send_header("Content-Length", str(len(body))) - self.send_header("Access-Control-Allow-Origin", "*") - self.send_header("Access-Control-Allow-Headers", "Content-Type, Authorization") - self.send_header("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE, OPTIONS") - # 让 file:// 打开的原型也能访问本机服务(Chrome 的 Private Network Access) - self.send_header("Access-Control-Allow-Private-Network", "true") + # 开发默认 *(file:// 打开的原型要能访问本机服务);生产默认不发这个头, + # 需要跨域就把域名写进 QINGLING_CORS。 + if CORS_ORIGINS: + origin = self.headers.get("Origin") or "" + if "*" in CORS_ORIGINS or origin in CORS_ORIGINS: + self.send_header("Access-Control-Allow-Origin", "*" if "*" in CORS_ORIGINS else origin) + self.send_header("Access-Control-Allow-Headers", "Content-Type, Authorization") + self.send_header("Access-Control-Allow-Methods", "GET, POST, PATCH, DELETE, OPTIONS") + # 让 file:// 打开的原型也能访问本机服务(Chrome 的 Private Network Access) + self.send_header("Access-Control-Allow-Private-Network", "true") for k, v in (extra or {}).items(): self.send_header(k, v) self.end_headers() @@ -491,7 +516,15 @@ class App(BaseHTTPRequestHandler): self._send(status, body, "application/json; charset=utf-8") def _read_body(self) -> tuple[dict, bytes]: - n = int(self.headers.get("Content-Length") or 0) + try: + n = int(self.headers.get("Content-Length") or 0) + except (TypeError, ValueError): + raise ApiError(400, "BAD_LENGTH", "Content-Length 不是数字") + if n < 0: + raise ApiError(400, "BAD_LENGTH", "Content-Length 不能是负数") + if n > MAX_BODY: + # 直连 8000 时没有 Caddy 的 16MB 兜底,这里自己拦一道 + raise ApiError(413, "BODY_TOO_LARGE", f"请求体太大了(上限 {MAX_BODY // (1024 * 1024)}MB)") raw = self.rfile.read(n) if n else b"" if not raw: return {}, raw @@ -601,6 +634,8 @@ class App(BaseHTTPRequestHandler): {"Cache-Control": "no-store"}) if isinstance(result, tuple) and result and result[0] == "png": return self._send(200, result[1], "image/png", {"Cache-Control": "no-store"}) + if isinstance(result, tuple) and result and result[0] == "jpg": + return self._send(200, result[1], "image/jpeg", {"Cache-Control": "no-store"}) if isinstance(result, tuple) and result and result[0] == "csv": name = result[2] if len(result) > 2 else "export.csv" return self._send(200, ("\ufeff" + result[1]).encode("utf-8"), @@ -614,7 +649,9 @@ class App(BaseHTTPRequestHandler): pass except Exception as e: # noqa: BLE001 traceback.print_exc() - self._json(500, {"ok": False, "error": {"code": "INTERNAL", "message": str(e)}}) + # 生产环境不把异常原文回给前端(会带出 SQL 和路径) + msg = "服务器内部错误,稍后再试" if PROD else str(e) + self._json(500, {"ok": False, "error": {"code": "INTERNAL", "message": msg}}) finally: try: conn.close() diff --git a/backend/db.py b/backend/db.py index fcd5461..977a5a9 100644 --- a/backend/db.py +++ b/backend/db.py @@ -63,6 +63,7 @@ CREATE TABLE IF NOT EXISTS papers ( image_count INTEGER NOT NULL DEFAULT 0, source TEXT NOT NULL DEFAULT 'camera', clean_path TEXT, + image_path TEXT, created_at TEXT NOT NULL ); @@ -286,7 +287,7 @@ def init_db(conn: sqlite3.Connection) -> None: def _migrate(conn: sqlite3.Connection) -> None: """老库补列(CREATE TABLE IF NOT EXISTS 不会改已存在的表)。""" want = {"questions": ["options", "kp"], "mistakes": ["options", "kp"], - "guardians": ["phone"], "papers": ["clean_path"]} + "guardians": ["phone"], "papers": ["clean_path", "image_path"]} for table, cols in want.items(): have = {r["name"] for r in conn.execute(f"PRAGMA table_info({table})").fetchall()} for c in cols: diff --git a/backend/services.py b/backend/services.py index eb459bd..93f5a3c 100644 --- a/backend/services.py +++ b/backend/services.py @@ -28,6 +28,15 @@ ADMIN_TOKEN_TTL = 7 * 24 * 3600 # 家长登录态 7 天 CHILD_TOKEN_TTL = 15 * 60 # 孩子口答会话 15 分钟 +def _session_expires_at() -> str: + """sessions 行上的到期时间。 + + 令牌本身带 HMAC 里的 exp(7 天),这一列是让人能直接在库里看懂会话什么时候失效。 + 以前这里写的是 datetime.now()——等于「创建即过期」,账本一直是假的。 + """ + return (datetime.now(TZ) + timedelta(seconds=ADMIN_TOKEN_TTL)).isoformat(timespec="seconds") + + class ApiError(Exception): def __init__(self, status: int, code: str, message: str): super().__init__(message) @@ -137,7 +146,7 @@ def login(conn, code: str) -> dict: log_event(conn, "login", None, guardian_id=row["id"], wx_mode=wechat.mode()) token = make_token(row["id"]) conn.execute("INSERT OR REPLACE INTO sessions (token, guardian_id, created_at, expires_at) VALUES (?,?,?,?)", - (token, row["id"], now(), datetime.now().isoformat(timespec="seconds"))) + (token, row["id"], now(), _session_expires_at())) ensure_trial(conn, row["id"]) return { "token": token, @@ -190,7 +199,7 @@ def login_ticket(conn, ticket: str) -> dict: gid = row["guardian_id"] token = make_token(gid) conn.execute("INSERT OR REPLACE INTO sessions (token, guardian_id, created_at, expires_at) VALUES (?,?,?,?)", - (token, gid, now(), datetime.now().isoformat(timespec="seconds"))) + (token, gid, now(), _session_expires_at())) ensure_trial(conn, gid) return { "token": token, "guardian_id": gid, "is_new": False, @@ -276,7 +285,7 @@ def login_phone(conn, phone: str, code: str) -> dict: token = make_token(grow["id"]) conn.execute("INSERT OR REPLACE INTO sessions (token, guardian_id, created_at, expires_at) VALUES (?,?,?,?)", - (token, grow["id"], now(), datetime.now().isoformat(timespec="seconds"))) + (token, grow["id"], now(), _session_expires_at())) ensure_trial(conn, grow["id"]) return { "token": token, "guardian_id": grow["id"], "is_new": is_new, @@ -689,6 +698,16 @@ def deletion_status(conn, gid: str) -> dict | None: return dict(row) if row else None +def purge_expired_sessions(conn) -> int: + """删掉已经过期的会话行。 + + 令牌过期后这些行没有任何用处;不删的话 sessions 会随登录次数一直长, + 而且这张表从来没被清理过(旧数据里 expires_at 还都是错的)。 + """ + cur = conn.execute("DELETE FROM sessions WHERE expires_at < ?", (now(),)) + return cur.rowcount or 0 + + def purge_due(conn) -> dict: """把过了冷静期的账号真删掉。每次登录与 health 都会顺手跑一次。""" rows = conn.execute("SELECT guardian_id FROM account_deletions WHERE purge_after <= ?", @@ -1307,6 +1326,55 @@ def demo_data(conn, gid: str, nickname: str = "皮皮", grade: int = 2) -> dict: # ---------------------------------------------------------------- 拍照识题 UPLOAD_DIR = Path(__file__).resolve().parent.parent / "data" / "uploads" + + +def _drop_upload(path: Path) -> None: + """删掉一个没能入库的上传文件——失败路径不留孤儿。""" + try: + if path and path.exists(): + path.unlink() + except OSError: + pass + + +def cleanup_uploads(conn, days: int = 90) -> int: + """删掉没人引用、且超过 days 天的上传文件。 + + 正常路径下 papers.image_path / clean_path 都有值;但 OCR 直接抛异常、 + 或者旧版本留下的文件可能只存在于磁盘。文件名主干就是 papers.id + (擦除页是 _clean),所以这里按「pid 还在不在 papers 里」兜底清一遍。 + """ + if not UPLOAD_DIR.exists(): + return 0 + alive = {r["id"] for r in conn.execute("SELECT id FROM papers")} + cutoff = time.time() - days * 86400 + n = 0 + for f in UPLOAD_DIR.rglob("*"): + try: + if not f.is_file() or f.stat().st_mtime >= cutoff: + continue + except OSError: + continue + pid = f.stem[:-6] if f.stem.endswith("_clean") else f.stem + if pid in alive: + continue + _drop_upload(f) + n += 1 + return n + + +_UPLOAD_SWEEP_AT = 0.0 + + +def sweep_uploads(conn, days: int = 90) -> int: + """每天最多扫一次上传目录——health 会被健康检查频繁打,不能每次都遍历磁盘。""" + global _UPLOAD_SWEEP_AT + if time.time() - _UPLOAD_SWEEP_AT < 86400: + return 0 + _UPLOAD_SWEEP_AT = time.time() + return cleanup_uploads(conn, days=days) + + ERASE_MIN_SIDE = 1200 # 短边不到这个尺寸就不擦:擦除会把印刷字也糊掉 @@ -1354,6 +1422,7 @@ def create_paper_from_image(conn, gid: str, cid: str, subject: str, image_bytes: ext = ".jpg" img_path = folder / f"{pid}{ext}" img_path.write_bytes(image_bytes) + clean_path_obj = folder / f"{pid}_clean.jpg" # 手写擦除(TextIn):干净页既能重印,也能让切题少被笔迹干扰。 # 图太小就别擦——这个接口在小图上会连印刷字一起抹掉,宁可不动。 @@ -1365,7 +1434,7 @@ def create_paper_from_image(conn, gid: str, cid: str, subject: str, image_bytes: erase = {"used": True, "ok": bool(r.get("ok")), "ms": r.get("ms")} if r.get("ok"): clean_rel = f"data/uploads/{cid}/{pid}_clean.jpg" - (folder / f"{pid}_clean.jpg").write_bytes(r["image"]) + clean_path_obj.write_bytes(r["image"]) erase["bytes"] = len(r["image"]) else: erase["reason"] = r.get("message") or r.get("code") @@ -1374,9 +1443,15 @@ def create_paper_from_image(conn, gid: str, cid: str, subject: str, image_bytes: else: erase["reason"] = "没配 TextIn 凭据" - res = ocr.recognize(img_path) - qual = ocr.quality(res) - questions = cut.segment(res["lines"], subject) if qual["ok"] else [] + try: + res = ocr.recognize(img_path) + qual = ocr.quality(res) + questions = cut.segment(res["lines"], subject) if qual["ok"] else [] + except Exception: + # OCR 自己崩了(没装语言包、子进程超时、图读不了):原图和擦除页都还没入库,删掉再抛 + _drop_upload(img_path) + _drop_upload(clean_path_obj) + raise if not qual["ok"] or not questions: if not qual["ok"]: @@ -1391,6 +1466,9 @@ def create_paper_from_image(conn, gid: str, cid: str, subject: str, image_bytes: f"把卷子拍全、让题号露出来;也可以先用演示题库走一遍。(认到:{preview}…)") if not fallback_demo: raise ApiError(422, code, (size_warn + " " + reason).strip() if size_warn else reason) + # 退回演示题库:这张图不会有任何 papers 行指向它,留在磁盘上就是孤儿 + _drop_upload(img_path) + _drop_upload(clean_path_obj) paper = create_paper(conn, gid, cid, subject, image_count=1) paper["source"] = "demo" paper["too_small"] = bool(size_warn) @@ -1401,9 +1479,10 @@ def create_paper_from_image(conn, gid: str, cid: str, subject: str, image_bytes: return paper with tx(conn): - conn.execute("INSERT INTO papers (id, child_id, subject, image_count, clean_path, created_at)" - " VALUES (?,?,?,?,?,?)", - (pid, cid, subject, 1, clean_rel, now())) + image_rel = f"data/uploads/{cid}/{img_path.name}" + conn.execute("INSERT INTO papers (id, child_id, subject, image_count, clean_path, image_path," + " created_at) VALUES (?,?,?,?,?,?,?)", + (pid, cid, subject, 1, clean_rel, image_rel, now())) for i, q in enumerate(questions, start=1): conn.execute( "INSERT INTO questions (id, paper_id, child_id, subject, seq, stem, answer, options," @@ -1488,7 +1567,7 @@ def _epoch() -> int: def _session_payload(conn, gid: str, via: str = "scan") -> dict: token = make_token(gid) conn.execute("INSERT OR REPLACE INTO sessions (token, guardian_id, created_at, expires_at) VALUES (?,?,?,?)", - (token, gid, now(), datetime.now().isoformat(timespec="seconds"))) + (token, gid, now(), _session_expires_at())) ensure_trial(conn, gid) log_event(conn, "login_" + via, None, guardian_id=gid) return { diff --git a/deploy/Caddyfile b/deploy/Caddyfile index 18b1884..5205932 100644 --- a/deploy/Caddyfile +++ b/deploy/Caddyfile @@ -4,8 +4,20 @@ {$SITE_DOMAIN} { encode zstd gzip - # 反代到容器里的 app(compose 网络内用服务名) - reverse_proxy app:8000 + # 开发接口(清库 / 签激活码 / 伪造扫码登录)只该在本机存在。 + # 应用层 QINGLING_ENV=prod 已经不注册它们,这里再兜一层: + # 就算有人把环境变量改回 dev,公网也打不到。 + handle /api/dev/* { + respond 404 + } + handle /api/auth/sms-* { + respond 404 + } + + # 其余请求反代到容器里的 app(compose 网络内用服务名) + handle { + reverse_proxy app:8000 + } header { # 安全响应头:这几个不影响功能,但漏了会被扫描器标出来 diff --git a/deploy/Dockerfile b/deploy/Dockerfile index c76358b..6946e02 100644 --- a/deploy/Dockerfile +++ b/deploy/Dockerfile @@ -1,7 +1,7 @@ # 错题毕业 · 小学版后端镜像 # -# 只依赖 Python 标准库,所以不用 pip install —— 这既是当时的限制,也成了优点: -# 镜像 150MB 左右、构建 10 秒、没有供应链风险。 +# 只依赖 Python 标准库,所以基本不用 pip install —— 这既是当时的限制,也成了优点: +# 镜像 150MB 左右、构建 10 秒、没有供应链风险。唯一例外见下面的 Pillow。 # # 注意:Linux 上没有 Windows OCR,拍照识题会走 OCR_HTTP_URL(见 deploy/README.md)。 FROM python:3.12-slim @@ -10,6 +10,11 @@ ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ TZ=Asia/Shanghai +# 唯一的第三方依赖:量图片尺寸(services.create_paper_from_image)。 +# 没有它的时候 img_w=img_h=0,于是「小图先拦一道」和「图太小就不做 TextIn 擦除」 +# 在容器里都会静默失效——本地装了 Pillow 所以一直没被发现。约 5MB,值。 +RUN pip install --no-cache-dir "pillow>=10,<12" + WORKDIR /app # 只拷运行需要的东西:接口、工作台页面、品牌标 diff --git a/deploy/README.md b/deploy/README.md index 1658b40..219737b 100644 --- a/deploy/README.md +++ b/deploy/README.md @@ -112,7 +112,7 @@ SQLite 用 `.backup`,不要 `cp`(WAL 下可能拷到半截)。上传的卷 ## 五、上线前检查清单 -- [ ] `api/health` 返回 `routes=50`、`version=1.2.0` +- [ ] `api/health` 返回 `version=1.2.0`;`routes` 在 prod 下是 49(dev 下 57,多出的 8 条是 6 个 `/api/dev/*` 与 2 个短信登录接口) - [ ] 手机号登录能收到验证码(**现在还是 dev 模式直接回显,必须接短信服务商**) - [ ] 小程序 `code2session` 能换到真 openid - [ ] 拍照识题返回 `source=ocr` @@ -120,6 +120,8 @@ SQLite 用 `.backup`,不要 `cp`(WAL 下可能拷到半截)。上传的卷 - [ ] 备份任务跑过一次、`/backup` 里有文件 - [ ] 数据目录权限正确(容器用户可写) - [ ] 关掉或限制 `/`(接口控制台)与 `/docs` +- [ ] `QINGLING_ENV=prod` 已生效:`POST /api/dev/reseed`、`/api/dev/issue-codes` 必须 404 +- [ ] Caddy 里 `/api/dev/*` 与 `/api/auth/sms-*` 返回 404(`curl -i https://<域名>/api/dev/reseed`) ## 六、回滚 diff --git a/deploy/docker-compose.yml b/deploy/docker-compose.yml index 632c08e..d4e0797 100644 --- a/deploy/docker-compose.yml +++ b/deploy/docker-compose.yml @@ -6,7 +6,7 @@ # docker compose up -d --build # docker compose logs -f app # -# 说明:app 只监听 127.0.0.1(通过 compose 内网给 caddy),公网只开 80/443。 +# 说明:app 在 compose 内网监听 8000,只由 caddy 反代;宿主不发布这个端口,公网只开 80/443。 services: app: @@ -27,6 +27,8 @@ services: OCR_HTTP_KEY: ${OCR_HTTP_KEY:-} # 数据库位置(挂卷) QINGLING_DB: /app/data/app.db + # 生产模式:不注册 /api/dev/* 与 /api/auth/sms-*(见 backend/app.py 的 PROD 开关) + QINGLING_ENV: ${QINGLING_ENV:-prod} volumes: - ../data:/app/data expose: