From 972bdde65038fd86182211f59ba3cf0164761579 Mon Sep 17 00:00:00 2001 From: jacy <18049821889@163.com> Date: Fri, 17 Jul 2026 09:30:09 +0800 Subject: [PATCH] fix(mini-user): restore production API origin for H5 builds Production builds were baking localhost:3000 after the local-dev default change, causing failed to fetch on product list. Co-authored-by: Cursor --- apps/mini-user/README.md | 2 +- apps/mini-user/config/index.ts | 6 ++++-- deploy/remote-release.sh | 2 ++ 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/apps/mini-user/README.md b/apps/mini-user/README.md index d38dac8..aeb33c7 100644 --- a/apps/mini-user/README.md +++ b/apps/mini-user/README.md @@ -18,7 +18,7 @@ pnpm --filter @dukang/mini-user dev:weapp | 环节 | 文件 | 说明 | |------|------|------| -| **编译注入** | `config/index.ts` → `defineConstants.TARO_APP_API_ORIGIN` | 默认 `http://localhost:3000`;连远程设 `VITE_API_TARGET=https://dkapi.runxian.top` | +| **编译注入** | `config/index.ts` → `defineConstants.TARO_APP_API_ORIGIN` | 本地默认 `http://localhost:3000`;`NODE_ENV=production` 默认 `https://dkapi.runxian.top`;可用 `VITE_API_TARGET` 覆盖 | | **运行时拼装** | `src/lib/api.ts` → `resolveApiBase()` | `{origin}/api/v1` | ### 微信登录 `invalid code` diff --git a/apps/mini-user/config/index.ts b/apps/mini-user/config/index.ts index 6d0556b..f7a0f1e 100644 --- a/apps/mini-user/config/index.ts +++ b/apps/mini-user/config/index.ts @@ -2,8 +2,10 @@ import { createRequire } from 'node:module'; import path from 'node:path'; import { defineConfig } from '@tarojs/cli'; -/** 小程序/H5 请求的后端 origin(不含 /api);发版/连远程请设 VITE_API_TARGET */ -const API_ORIGIN = process.env.VITE_API_TARGET ?? 'http://localhost:3000'; +/** 小程序/H5 请求的后端 origin(不含 /api);本地默认本机,生产构建默认远程 */ +const API_ORIGIN = + process.env.VITE_API_TARGET ?? + (process.env.NODE_ENV === 'production' ? 'https://dkapi.runxian.top' : 'http://localhost:3000'); const requireFromApp = createRequire(path.resolve(__dirname, '../package.json')); diff --git a/deploy/remote-release.sh b/deploy/remote-release.sh index fdf8554..cde0476 100644 --- a/deploy/remote-release.sh +++ b/deploy/remote-release.sh @@ -46,6 +46,8 @@ export NODE_OPTIONS="${NODE_OPTIONS:---max-old-space-size=8192}" # 生产部署 path:nginx 入口为 /user/ export TARO_H5_PUBLIC_PATH="${TARO_H5_PUBLIC_PATH:-/user/}" export TARO_H5_ROUTER_BASENAME="${TARO_H5_ROUTER_BASENAME:-/user}" +# C 端 H5 编译期注入的 API origin(勿落到 localhost) +export VITE_API_TARGET="${VITE_API_TARGET:-https://dkapi.runxian.top}" pnpm approve-builds --all 2>/dev/null || true pnpm install --frozen-lockfile 2>/dev/null || pnpm install