From 8f83624ffeaecf97de7b10e286da95bda8acaa64 Mon Sep 17 00:00:00 2001 From: jacy <18049821889@163.com> Date: Fri, 7 Aug 2026 21:03:23 +0800 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFchore(dev):=20move=20local=20API=20def?= =?UTF-8?q?ault=20port=20to=203010?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Avoid conflict with another local service on 3000; align Vite proxies and docs. --- .cursor/skills/dukang-coding/reference-frontend.md | 2 +- AGENTS.md | 4 ++-- apps/admin-web/vite.config.ts | 4 +++- apps/h5-partner/vite.config.ts | 2 +- apps/h5-shop/vite.config.ts | 2 +- apps/h5-user/vite.config.ts | 2 +- apps/mini-hq/config/index.ts | 4 ++-- apps/mini-hq/src/lib/api.ts | 2 +- apps/mini-user/README.md | 4 ++-- apps/mini-user/config/index.ts | 2 +- apps/mini-user/src/lib/api.ts | 2 +- server/dukang-api/.env.example | 2 +- server/dukang-api/src/main.ts | 2 +- 13 files changed, 18 insertions(+), 16 deletions(-) diff --git a/.cursor/skills/dukang-coding/reference-frontend.md b/.cursor/skills/dukang-coding/reference-frontend.md index d70bc98..706c978 100644 --- a/.cursor/skills/dukang-coding/reference-frontend.md +++ b/.cursor/skills/dukang-coding/reference-frontend.md @@ -13,7 +13,7 @@ > **h5-partner 与 admin-web 端口同为 5175**,勿同时 `dev:partner` + `dev:admin`。 -Vite 代理:`/api` → `localhost:3000`。 +Vite 代理:`/api` → `localhost:3010`(可用 `VITE_API_TARGET` 覆盖)。 ## 共享包 diff --git a/AGENTS.md b/AGENTS.md index bd34d40..c5547de 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -28,7 +28,7 @@ pnpm db:generate && pnpm db:validate cd server/dukang-api && npx prisma db push && pnpm prisma:seed # 开发(分终端) -pnpm dev:api # http://localhost:3000/api/v1 +pnpm dev:api # http://localhost:3010/api/v1 pnpm dev:user # :5173 pnpm dev:shop # :5174 pnpm dev:partner # :5175 @@ -144,7 +144,7 @@ C 端门店仅 status=OPEN | 环境 | 分支 | 目录 | 端口 | 域名 | |------|------|------|------|------| -| local | `dev_jacy` | 本机 Docker 6016/6017 | API `:3000` | — | +| local | `dev_jacy` | 本机 Docker 6016/6017 | API `:3010` | — | | **staging 测试** | `dev` | `/opt/dukang-staging` | 8190–8194 | `*-test.dukanghaoke.com` | | **production 生产** | `main` | `/opt/dukang` | 8090–8094 | `*.dukanghaoke.com` | diff --git a/apps/admin-web/vite.config.ts b/apps/admin-web/vite.config.ts index 62266b2..44d5d94 100644 --- a/apps/admin-web/vite.config.ts +++ b/apps/admin-web/vite.config.ts @@ -1,10 +1,12 @@ import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; +const apiTarget = process.env.VITE_API_TARGET ?? 'http://localhost:3010'; + export default defineConfig({ plugins: [react()], server: { port: 5175, - proxy: { '/api': 'http://localhost:3000' }, + proxy: { '/api': apiTarget }, }, }); diff --git a/apps/h5-partner/vite.config.ts b/apps/h5-partner/vite.config.ts index 0babaf1..ef72a3e 100644 --- a/apps/h5-partner/vite.config.ts +++ b/apps/h5-partner/vite.config.ts @@ -14,7 +14,7 @@ export default defineConfig({ server: { port: 5175, proxy: { - '/api': process.env.VITE_API_TARGET ?? 'http://localhost:3000', + '/api': process.env.VITE_API_TARGET ?? 'http://localhost:3010', }, }, }); \ No newline at end of file diff --git a/apps/h5-shop/vite.config.ts b/apps/h5-shop/vite.config.ts index 40e1eb8..803f41b 100644 --- a/apps/h5-shop/vite.config.ts +++ b/apps/h5-shop/vite.config.ts @@ -13,6 +13,6 @@ export default defineConfig({ }, server: { port: 5174, - proxy: { '/api': 'http://localhost:3000' }, + proxy: { '/api': process.env.VITE_API_TARGET ?? 'http://localhost:3010' }, }, }); \ No newline at end of file diff --git a/apps/h5-user/vite.config.ts b/apps/h5-user/vite.config.ts index 5daf8b8..8fa7010 100644 --- a/apps/h5-user/vite.config.ts +++ b/apps/h5-user/vite.config.ts @@ -13,7 +13,7 @@ export default defineConfig({ }, server: { proxy: { - '/api': 'http://localhost:3000', + '/api': process.env.VITE_API_TARGET ?? 'http://localhost:3010', }, }, }); \ No newline at end of file diff --git a/apps/mini-hq/config/index.ts b/apps/mini-hq/config/index.ts index 322e267..38c0a10 100644 --- a/apps/mini-hq/config/index.ts +++ b/apps/mini-hq/config/index.ts @@ -16,7 +16,7 @@ export default defineConfig(async () => ({ plugins: ['@tarojs/plugin-html'], defineConstants: { /** H5 静态托管无 /api 代理时直连后端;dev 构建可通过 VITE_API_TARGET 覆盖 */ - TARO_APP_API_ORIGIN: JSON.stringify(process.env.VITE_API_TARGET ?? 'http://localhost:3000'), + TARO_APP_API_ORIGIN: JSON.stringify(process.env.VITE_API_TARGET ?? 'http://localhost:3010'), }, copy: { patterns: [], @@ -44,7 +44,7 @@ export default defineConfig(async () => ({ host: '0.0.0.0', proxy: { '/api': { - target: process.env.VITE_API_TARGET ?? 'http://localhost:3000', + target: process.env.VITE_API_TARGET ?? 'http://localhost:3010', changeOrigin: true, }, }, diff --git a/apps/mini-hq/src/lib/api.ts b/apps/mini-hq/src/lib/api.ts index d7baeb6..23a78d5 100644 --- a/apps/mini-hq/src/lib/api.ts +++ b/apps/mini-hq/src/lib/api.ts @@ -5,7 +5,7 @@ function resolveApiBase(): string { typeof TARO_APP_API_ORIGIN !== 'undefined' && TARO_APP_API_ORIGIN ? TARO_APP_API_ORIGIN : process.env.TARO_ENV === 'h5' - ? 'http://localhost:3000' + ? 'http://localhost:3010' : ''; if (origin) { return `${origin.replace(/\/$/, '')}/api/v1`; diff --git a/apps/mini-user/README.md b/apps/mini-user/README.md index 3906c93..140d584 100644 --- a/apps/mini-user/README.md +++ b/apps/mini-user/README.md @@ -21,7 +21,7 @@ pnpm build:mini-user:weapp | 环节 | 文件 | 说明 | |------|------|------| -| **编译注入** | `config/index.ts` → `defineConstants.TARO_APP_API_ORIGIN` | `dev:weapp` / watch → `localhost:3000`;`build:weapp`(`--mode production`)→ `https://api.dukanghaoke.com`;可用 `VITE_API_TARGET` 覆盖 | +| **编译注入** | `config/index.ts` → `defineConstants.TARO_APP_API_ORIGIN` | `dev:weapp` / watch → `localhost:3010`;`build:weapp`(`--mode production`)→ `https://api.dukanghaoke.com`;可用 `VITE_API_TARGET` 覆盖 | | **运行时拼装** | `src/lib/api.ts` → `resolveApiBase()` | `{origin}/api/v1` | ### 微信登录 `invalid code` @@ -33,7 +33,7 @@ pnpm build:mini-user:weapp | 小程序 appid | `project.config.json` → `wxda31c8e8e85051e7` | | 后端须配置 | `WX_MINI_APP_ID` / `WX_MINI_APP_SECRET`(与上表一致) | -**本地联调(不接真实微信)**:保持默认即可(API → `localhost:3000`),并开启 Mock: +**本地联调(不接真实微信)**:保持默认即可(API → `localhost:3010`),并开启 Mock: ```bash # 终端 1 diff --git a/apps/mini-user/config/index.ts b/apps/mini-user/config/index.ts index 10d1eef..ced7c2f 100644 --- a/apps/mini-user/config/index.ts +++ b/apps/mini-user/config/index.ts @@ -11,7 +11,7 @@ const isDevMode = /** 小程序/H5 请求的后端 origin(不含 /api);本地默认本机,生产构建默认远程 */ const API_ORIGIN = process.env.VITE_API_TARGET ?? - (isDevMode ? 'http://localhost:3000' : 'https://api.dukanghaoke.com'); + (isDevMode ? 'http://localhost:3010' : 'https://api.dukanghaoke.com'); const requireFromApp = createRequire(path.resolve(__dirname, '../package.json')); diff --git a/apps/mini-user/src/lib/api.ts b/apps/mini-user/src/lib/api.ts index de524fe..f50d221 100644 --- a/apps/mini-user/src/lib/api.ts +++ b/apps/mini-user/src/lib/api.ts @@ -10,7 +10,7 @@ function resolveApiBase(): string { typeof TARO_APP_API_ORIGIN !== 'undefined' && TARO_APP_API_ORIGIN ? TARO_APP_API_ORIGIN : process.env.TARO_ENV === 'h5' - ? 'http://localhost:3000' + ? 'http://localhost:3010' : ''; if (origin) { return `${origin.replace(/\/$/, '')}/api/v1`; diff --git a/server/dukang-api/.env.example b/server/dukang-api/.env.example index bc5c72b..eddca5c 100644 --- a/server/dukang-api/.env.example +++ b/server/dukang-api/.env.example @@ -8,7 +8,7 @@ DATABASE_URL="mysql://root:root@localhost:6016/dukang_haoke" REDIS_URL="redis://localhost:6017" JWT_SECRET="dukang-prev1-dev-secret-change-in-prod" JWT_EXPIRES_IN="7d" -PORT=3000 +PORT=3010 MOCK_SMS=true # MOCK_SMS=false 时必填(可与 OSS 共用 RAM) ALIYUN_SMS_SIGN_NAME= diff --git a/server/dukang-api/src/main.ts b/server/dukang-api/src/main.ts index 3480393..3828a4b 100644 --- a/server/dukang-api/src/main.ts +++ b/server/dukang-api/src/main.ts @@ -86,7 +86,7 @@ async function bootstrap() { app.useGlobalPipes(new ValidationPipe({ transform: true, whitelist: true })); app.useGlobalFilters(new HttpExceptionFilter(app.get(AlertService))); app.useGlobalInterceptors(new ResponseInterceptor(), app.get(LoggingInterceptor)); - const port = process.env.PORT || 3000; + const port = process.env.PORT || 3010; const cfg = loadAppConfig(); const smsMode = cfg.mockSms ? 'MOCK' : 'ALIYUN'; console.log(`[config] NODE_ENV=${process.env.NODE_ENV} MOCK_SMS=${cfg.mockSms} SMS=${smsMode}`);