From 3b169df114fe130f2368ae0d7507da59db98e69c Mon Sep 17 00:00:00 2001 From: yml Date: Tue, 14 Apr 2026 23:27:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E6=9C=8D=E5=8A=A1=E7=AB=AF?= =?UTF-8?q?=E9=83=A8=E7=BD=B2-=E6=B5=8B=E8=AF=95=E9=83=A8=E7=BD=B2-1?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .env.development.example | 28 ------------------ .env.mac-docker.example | 46 ++++++++++++++++++++++++++++++ .env.production.example | 25 ---------------- .env.服务端 => .env.server.example | 21 ++++++++++++-- CLAUDE.md | 4 +-- README.md | 33 ++++++++++++++++----- apps/backend/README.md | 2 +- deploy/data/backend/.gitkeep | 1 + docker-compose.yml | 3 +- 9 files changed, 96 insertions(+), 67 deletions(-) delete mode 100644 .env.development.example create mode 100644 .env.mac-docker.example delete mode 100644 .env.production.example rename .env.服务端 => .env.server.example (56%) create mode 100644 deploy/data/backend/.gitkeep diff --git a/.env.development.example b/.env.development.example deleted file mode 100644 index 1194953f..00000000 --- a/.env.development.example +++ /dev/null @@ -1,28 +0,0 @@ -# 当前模板用于 mac 本机 Docker 测试。 -# 开发版 Caddy 会接受任意 Host,所以 ngrok / cloudflared 地址变化时通常只需要改 APP_BASE_URL。 -APP_BASE_URL=http://localhost - -# 如需给外部用户发送领取链接,把 APP_BASE_URL 改成当前公网地址。 -# 只有当领取页入口与整站入口不同,才需要单独覆盖 CLAIM_BASE_URL。 -TZ=Asia/Shanghai -BACKEND_PORT=3000 -CLAIM_BASE_URL=http://localhost/#/claim -DATABASE_URL=postgres://postgres:postgres@postgres:5432/order_site -DATABASE_SSL=false -DATABASE_MAX_CONNECTIONS=10 -DATA_ROOT=/app/data -LOG_LEVEL=info -OCR_PROJECT_ROOT=/app/subservices/ocr-worker -TENCENT_REDEEM_PROOF_MODE=basic -TENCENT_BROWSER_HEADLESS=true -TENCENT_BROWSER_DEVTOOLS=false -TENCENT_BROWSER_PREWARM=true -TENCENT_BROWSER_KEEP_ALIVE=true -TENCENT_BROWSER_SLOW_MO=0 -TENCENT_SESSION_DEBUG=false - -ADMIN_SESSION_SECRET=dev-local-session-secret -ADMIN_DEFAULT_USERS_JSON=[{"username":"admin","password":"dev-admin-123456","role":"admin"},{"username":"operator","password":"dev-operator-123456","role":"operator"}] - -AGISO_APP_SECRET= -AGISO_MESSAGING_ENABLED=false diff --git a/.env.mac-docker.example b/.env.mac-docker.example new file mode 100644 index 00000000..655a5775 --- /dev/null +++ b/.env.mac-docker.example @@ -0,0 +1,46 @@ +# 当前模板用于 mac 本机 Docker 调试。 +# 开发版 Caddy 会接受任意 Host;如果你要给外部用户发领取链接, +# 只需要把 APP_BASE_URL / CLAIM_BASE_URL 改成当前公网地址。 +APP_BASE_URL=http://localhost + +TZ=Asia/Shanghai +BACKEND_PORT=3000 +CLAIM_BASE_URL=http://localhost/#/claim + +POSTGRES_DB=order_site +POSTGRES_USER=postgres +POSTGRES_PASSWORD=postgres +DATABASE_URL=postgres://postgres:postgres@postgres:5432/order_site +DATABASE_SSL=false +DATABASE_MAX_CONNECTIONS=10 + +DATA_ROOT=/app/data +LOG_LEVEL=info +OCR_PROJECT_ROOT=/app/subservices/ocr-worker + +TENCENT_REDEEM_PROOF_MODE=basic +TENCENT_BROWSER_HEADLESS=false +TENCENT_BROWSER_DEVTOOLS=false +TENCENT_BROWSER_PREWARM=true +TENCENT_BROWSER_KEEP_ALIVE=true +TENCENT_BROWSER_SLOW_MO=200 +TENCENT_SESSION_DEBUG=true +TENCENT_BROWSER_NOVNC_ENABLED=true +TENCENT_BROWSER_NOVNC_PORT=6080 +TENCENT_BROWSER_VNC_PORT=5900 +TENCENT_BROWSER_VNC_RESOLUTION=1600x900x24 + +ADMIN_SESSION_SECRET=dev-local-session-secret +ADMIN_SESSION_TTL_HOURS=12 +ADMIN_DEFAULT_USERS_JSON=[{"username":"admin","password":"dev-admin-123456","role":"admin"},{"username":"operator","password":"dev-operator-123456","role":"operator"}] + +AGISO_APP_SECRET= +AGISO_MESSAGING_ENABLED=true +AGISO_TRADE_DETAIL_ENDPOINT=https://gw-api.agiso.com/aldsIdle/Order/Detail +AGISO_TRADE_DETAIL_API_VERSION=1 +AGISO_TRADE_DETAIL_TIMEOUT_MS=5000 +AGISO_AUTO_DELIVERY_ENABLED=true +AGISO_AUTO_DELIVERY_ENDPOINT=https://gw-api.agiso.com/aldsIdle/Order/DummySend +AGISO_AUTO_DELIVERY_API_VERSION=1 +AGISO_MESSAGE_API_VERSION=1 +AGISO_SEND_MESSAGE_ENDPOINT=https://gw-api.agiso.com/aldsIdle/ImMsg/SendMsg diff --git a/.env.production.example b/.env.production.example deleted file mode 100644 index 039b992c..00000000 --- a/.env.production.example +++ /dev/null @@ -1,25 +0,0 @@ -APP_DOMAIN=order.example.com -APP_BASE_URL=https://order.example.com - -TZ=Asia/Shanghai -BACKEND_PORT=3000 -CLAIM_BASE_URL=https://order.example.com/#/claim -DATABASE_URL=postgres://postgres:replace-with-strong-password@postgres:5432/order_site -DATABASE_SSL=false -DATABASE_MAX_CONNECTIONS=20 -DATA_ROOT=/app/data -LOG_LEVEL=info -OCR_PROJECT_ROOT=/app/subservices/ocr-worker -TENCENT_REDEEM_PROOF_MODE=basic -TENCENT_BROWSER_HEADLESS=true -TENCENT_BROWSER_DEVTOOLS=false -TENCENT_BROWSER_PREWARM=true -TENCENT_BROWSER_KEEP_ALIVE=true -TENCENT_BROWSER_SLOW_MO=0 -TENCENT_SESSION_DEBUG=false - -ADMIN_SESSION_SECRET=replace-with-a-long-random-secret -ADMIN_DEFAULT_USERS_JSON=[{"username":"admin","password":"replace-with-strong-admin-password","role":"admin"},{"username":"operator","password":"replace-with-strong-operator-password","role":"operator"}] - -AGISO_APP_SECRET= -AGISO_MESSAGING_ENABLED=false diff --git a/.env.服务端 b/.env.server.example similarity index 56% rename from .env.服务端 rename to .env.server.example index 156edfdc..a893b1e3 100644 --- a/.env.服务端 +++ b/.env.server.example @@ -1,16 +1,24 @@ APP_DOMAIN=order.khhao.com APP_BASE_URL=https://order.khhao.com +CADDY_SITE_ADDR=https://order.khhao.com TZ=Asia/Shanghai BACKEND_PORT=3000 CLAIM_BASE_URL=https://order.khhao.com/#/claim +CLAIM_TOKEN_TTL_HOURS=24 + +POSTGRES_DB=order_site +POSTGRES_USER=postgres +POSTGRES_PASSWORD=FACCqheAzy51op0RFdbv DATABASE_URL=postgres://postgres:FACCqheAzy51op0RFdbv@postgres:5432/order_site DATABASE_SSL=false DATABASE_MAX_CONNECTIONS=20 + DATA_ROOT=/app/data LOG_LEVEL=info OCR_PROJECT_ROOT=/app/subservices/ocr-worker -TENCENT_REDEEM_PROOF_MODE=basic + +TENCENT_REDEEM_PROOF_MODE=full TENCENT_BROWSER_HEADLESS=true TENCENT_BROWSER_DEVTOOLS=false TENCENT_BROWSER_PREWARM=true @@ -19,7 +27,16 @@ TENCENT_BROWSER_SLOW_MO=0 TENCENT_SESSION_DEBUG=false ADMIN_SESSION_SECRET=xm4BDpbdHJvU4RIlpGqD0nvQTZtIidvQMk6LSP1d +ADMIN_SESSION_TTL_HOURS=12 ADMIN_DEFAULT_USERS_JSON=[{"username":"admin","password":"Mzl5iG6pkdrzLs73COiB","role":"admin"},{"username":"operator","password":"d9tvmbPPMRdLySEhORzk","role":"operator"}] AGISO_APP_SECRET=tccxk5c7ppy7xpr43rvastceyydskfha -AGISO_MESSAGING_ENABLED=false +AGISO_MESSAGING_ENABLED=true +AGISO_TRADE_DETAIL_ENDPOINT=https://gw-api.agiso.com/aldsIdle/Order/Detail +AGISO_TRADE_DETAIL_API_VERSION=1 +AGISO_TRADE_DETAIL_TIMEOUT_MS=5000 +AGISO_AUTO_DELIVERY_ENABLED=true +AGISO_AUTO_DELIVERY_ENDPOINT=https://gw-api.agiso.com/aldsIdle/Order/DummySend +AGISO_AUTO_DELIVERY_API_VERSION=1 +AGISO_MESSAGE_API_VERSION=1 +AGISO_SEND_MESSAGE_ENDPOINT=https://gw-api.agiso.com/aldsIdle/ImMsg/SendMsg diff --git a/CLAUDE.md b/CLAUDE.md index 5864e6e1..ea225a8e 100644 --- a/CLAUDE.md +++ b/CLAUDE.md @@ -44,7 +44,7 @@ This file provides guidance to Claude Code (claude.ai/code) when working with co ### Local Development (without Docker) ```bash # Backend -cp .env.development.example .env +cp .env.mac-docker.example .env cd apps/backend npm install npm run dev # node --watch restart on src/ changes @@ -61,7 +61,7 @@ uv sync ### Docker Development (recommended) ```bash -cp .env.development.example .env +cp .env.mac-docker.example .env docker compose -f docker-compose.dev.yml up -d --build # Access: http://localhost, noVNC: http://localhost:6080/vnc.html ``` diff --git a/README.md b/README.md index ff50b735..d4fec383 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ npm run dev 后端: ```bash -cp .env.development.example .env +cp .env.mac-docker.example .env cd apps/backend/subservices/ocr-worker uv sync cd apps/backend @@ -39,15 +39,34 @@ npm run dev ## Docker 部署 ```bash -cp .env.production.example .env -docker compose build +cp .env.server.example .env +mkdir -p deploy/data/backend docker compose up -d ``` +生产版 Compose 现在会把后端运行数据直接挂载到宿主机目录: + +- `deploy/data/backend` + +这样服务器上可以直接查看和备份: + +- `logs/` +- `browser-sessions/` +- `redeem-screenshots/` +- `agiso-shops.json` +- `order-fulfillment-bindings.json` + +如果你本地已经配好了店铺和履约绑定,首次上线前可以把这两份文件先放进去: + +- `deploy/data/backend/agiso-shops.json` +- `deploy/data/backend/order-fulfillment-bindings.json` + +后端启动时会自动执行数据库 migration、初始化默认管理员、同步履约目录;但 `/app/data` 下的业务配置文件仍以宿主机目录内容为准。 + ## Docker 本地开发 ```bash -cp .env.development.example .env +cp .env.mac-docker.example .env docker compose -f docker-compose.dev.yml up -d --build ``` @@ -126,12 +145,12 @@ docker compose build \ - [服务器部署教程](/Users/yml/codes/order-site-workspace/docs/%E6%9C%8D%E5%8A%A1%E5%99%A8%E9%83%A8%E7%BD%B2%E6%95%99%E7%A8%8B.md) - [首次上线检查清单](/Users/yml/codes/order-site-workspace/docs/%E9%A6%96%E6%AC%A1%E4%B8%8A%E7%BA%BF%E6%A3%80%E6%9F%A5%E6%B8%85%E5%8D%95.md) -- [开发环境模板](/Users/yml/codes/order-site-workspace/.env.development.example) -- [生产环境模板](/Users/yml/codes/order-site-workspace/.env.production.example) +- [mac 本地 Docker 调试模板](/Users/yml/codes/order-site-workspace/.env.mac-docker.example) +- [服务器部署模板](/Users/yml/codes/order-site-workspace/.env.server.example) ## 迁移原则 - 不重写现有业务代码 - 先统一目录、部署和配置 -- 生产环境优先使用 `.env` 和 Docker 卷 +- 生产环境优先使用 `.env` 和宿主机数据目录挂载 - 本机 Docker 调试优先使用 [docker-compose.dev.yml](/Users/yml/codes/order-site-workspace/docker-compose.dev.yml) diff --git a/apps/backend/README.md b/apps/backend/README.md index deddb9ff..b5c30321 100644 --- a/apps/backend/README.md +++ b/apps/backend/README.md @@ -27,7 +27,7 @@ uv sync 复制并填写环境变量后启动: ```bash -cp /Users/yml/codes/order-site-workspace/.env.development.example /Users/yml/codes/order-site-workspace/.env +cp /Users/yml/codes/order-site-workspace/.env.mac-docker.example /Users/yml/codes/order-site-workspace/.env cd /Users/yml/codes/order-site-workspace/apps/backend npm run dev ``` diff --git a/deploy/data/backend/.gitkeep b/deploy/data/backend/.gitkeep new file mode 100644 index 00000000..8b137891 --- /dev/null +++ b/deploy/data/backend/.gitkeep @@ -0,0 +1 @@ + diff --git a/docker-compose.yml b/docker-compose.yml index 7222a1cf..d90fa0b6 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -50,7 +50,7 @@ services: AGISO_MESSAGING_ENABLED: ${AGISO_MESSAGING_ENABLED:-false} AGISO_MESSAGE_APP_SECRET: ${AGISO_MESSAGE_APP_SECRET:-} volumes: - - backend_data:/app/data + - ./deploy/data/backend:/app/data web: build: @@ -74,7 +74,6 @@ services: - caddy_config:/config volumes: - backend_data: postgres_data: caddy_data: caddy_config: