@lark-apaas/coding-steering 0.1.8 → 0.1.9

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lark-apaas/coding-steering",
3
- "version": "0.1.8",
3
+ "version": "0.1.9",
4
4
  "description": "Stack-specific steering content for miaoda-coding templates",
5
5
  "type": "module",
6
6
  "files": [
@@ -16,6 +16,9 @@
16
16
  "access": "public",
17
17
  "registry": "https://registry.npmjs.org/"
18
18
  },
19
+ "chiya": {
20
+ "markdownIsSource": true
21
+ },
19
22
  "keywords": [
20
23
  "miaoda",
21
24
  "coding-steering"
@@ -367,17 +367,30 @@ async createArticle(@Req() req: Request, @Body() dto: CreateArticleDto) {
367
367
 
368
368
  ## 本地 dev API 调试
369
369
 
370
- ### 入口端口:**只走 vite/rspack dev server**
370
+ ### 入口端口和 base path:**只走 vite/rspack dev server**
371
371
 
372
- 本地 dev 跑起来有**两个端口**:
372
+ 本地 dev 跑起来有**两个端口 + 一个前缀**,都由 `.env.local` 里的 env 控制:
373
373
 
374
- | 端口 | 进程 | env | 默认 | 角色 |
374
+ | Env | 进程 / 用途 | 默认 | 沙箱 env-pull 下发? | 备注 |
375
375
  |---|---|---|---|---|
376
- | **client dev port** | vite / rspack | `CLIENT_DEV_PORT` | `8080` | **唯一入口**:serve 前端 + 反代 `/api/*` 给 NestJS + 注入 `x-larkgw-suda-webuser` 模拟登录态 |
377
- | nest server port | NestJS | `SERVER_PORT` | `3000` | 仅 vite/rspack 反代用,不直接给 agent / curl |
376
+ | `CLIENT_DEV_PORT` | vite / rspack dev server | `8080` | ❌ 不下发 | **唯一入口**:serve 前端 + 反代 `/api/*` 给 NestJS + 注入 `x-larkgw-suda-webuser` 模拟登录态。端口被占就 Agent 自己改 `.env.local` |
377
+ | `SERVER_PORT` | NestJS | `3000` | 不下发 | 仅 vite/rspack 反代用,不直接给 agent / curl 用。端口被占就 Agent 自己改 `.env.local` |
378
+ | `CLIENT_BASE_PATH` | 前端路由 base + 后端 routes.json serve 路径 | `/` | ✅ `/app/<app_id>` | 浏览器 URL 前缀;agent / curl 调 `/api/*` 也必须带这个前缀 |
378
379
 
379
- 启动日志里 vite/rspack 打印的 `Local: http://localhost:<CLIENT_DEV_PORT>/...` 才是入口
380
- (具体端口看 `.env.local` `CLIENT_DEV_PORT`,常见值是 `8080` `8001`)。
380
+ 完整入口形态 = `http://localhost:<CLIENT_DEV_PORT><CLIENT_BASE_PATH>/...`。启动日志里
381
+ vite/rspack 打印的 `Local: http://localhost:<port>/...` 才是入口,具体值以 `.env.local`
382
+ 为准(沙箱 `lark-cli +env-pull` 会把 `CLIENT_BASE_PATH` 下发成 `/app/<app_id>`,本地裸
383
+ 跑不设则退到 `/`)。
384
+
385
+ > **端口冲突时**:`CLIENT_DEV_PORT` / `SERVER_PORT` 不归 env-pull 管,Agent 自己在
386
+ > `.env.local` 加 `CLIENT_DEV_PORT=8001`(或别的空闲端口)然后重启 `npm run dev`
387
+ > 即可。**不要去改 `vite.config.ts` / NestJS bootstrap 里的硬编码端口**,preset 已经
388
+ > 自己读这两个 env,业务侧改源码反而会跟 sandbox 配置发散。
389
+
390
+ > **dev vs prod 的 base path 差异**:dev 模式下 vite/rspack 把前端组件 basePath 强制
391
+ > 成 `''`(preset 里 `isDev ? { basePath: '' } : ...`),所以前端 router 用相对路径就
392
+ > 行;但 dev server 自己 serve 路由 / 反代 `/api/*` 的路径**仍然带 `CLIENT_BASE_PATH`
393
+ > 前缀**,浏览器 URL 跟 prod 一样长。这也是 agent / curl 必须带前缀的原因。
381
394
 
382
395
  **绕过 vite/rspack 直连 NestJS 端口的后果**:vite/rspack dev server 是从
383
396
  `SUDA_WEBUSER` env 读出 webuser 拼到 `x-larkgw-suda-webuser` header 再转发给 NestJS 的,
@@ -401,10 +414,11 @@ NestJS 自己不读 env。直连 NestJS 端口 → header 缺失 → `req.userCo
401
414
  NestJS 端口):
402
415
 
403
416
  ```bash
404
- # <PORT> = .env.local 里的 CLIENT_DEV_PORT,常见 8080 / 8001
417
+ # <PORT> = .env.local 里的 CLIENT_DEV_PORT(常见 8080 / 8001
418
+ # <BASE_PATH> = .env.local 里的 CLIENT_BASE_PATH(沙箱下发为 /app/<app_id>,本地裸跑可能为空)
405
419
  curl -H 'Cookie: suda-csrf-token=x' \
406
420
  -H 'X-Suda-Csrf-Token: x' \
407
- http://localhost:<PORT>/app/<app_id>/api/notes
421
+ http://localhost:<PORT><BASE_PATH>/api/notes
408
422
  ```
409
423
 
410
424
  **不要**因为撞 403 就去改后端 csrf 中间件或者怀疑业务逻辑 —— csrf 保护是有意的,