nomadro/.cursor/skills/local-frontend-online-backend/SKILL.md

50 lines
2.5 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

---
name: local-frontend-online-backend
description: >-
Hard gate: local frontend must talk to online .com backends, not localhost
FastAPI by default. Use when configuring WORK_API_URL / COFFEE_API_URL /
NOTIFY_API_URL / API_URL, pnpm dev, or fixing「无法连接 work API」on localhost.
---
# 本地前端直连线上后端(写死)
## 铁律(逐字)
**本地前端直连线上后端。**
`pnpm dev` / `localhost:3000` 的业务 API **默认**打 **`https://nomadro.com`**(美国机线上),**禁止**默认假设本机已起 `dev:work-api` / `8021` / `8023` / `8024`。
## 默认上游
| 本地 Next 路径 | 环境变量 | 默认值(无 env 时) |
|----------------|----------|---------------------|
| `/api/work/v1/*` | `WORK_API_URL` | `https://nomadro.com` |
| `/api/notify/v1/*` | `NOTIFY_API_URL` | `https://nomadro.com` |
| `/api/coffee/v1/*` | `COFFEE_API_URL` | `https://nomadro.com` |
| 其它门户业务 | `API_URL` | `https://nomadro.com` |
| 远程配置(浏览器) | `NEXT_PUBLIC_REMOTE_CONFIG_URL` | `https://nomadro.com/api/config` |
代理拼法:`{ORIGIN}/api/work/v1/...` —— **只写站点根**(`https://nomadro.com`),不要写成带 `/api/work/v1` 的完整前缀以免双拼。
## 反模式(禁止)
- `.env.local` 默认 `WORK_API_URL=http://127.0.0.1:8021`,导致 pads「请先启动 pnpm dev:work-api」
- 代码默认 `127.0.0.1:802x` 却对用户说「本地开前端就能用」
- 为躲线上后端,把本地 offline JSON 当成主路径(offline **仅**线上不可达时兜底)
- 要求用户「再开一个 work-api 终端」才算本地可用
## 唯一例外
用户**本轮明确**说要联调本机后端(例如「起本地 work-api」「WORK_API_URL 指 8021」)时,才允许 `.env.local` 指向 `127.0.0.1:802x`。
## Agent 行为
1. 改 work/notify/coffee 代理或 `.env*` 时先读本 skill。
2. 发现默认仍是 localhost → **立刻改成** `https://nomadro.com`。
3. 本地 pads/boards 连不上 → 先查是否误指 127.0.0.1,再查线上 `https://nomadro.com/api/work/v1/health`。
4. **不要**为修本地连通性去上线前端(见 `no-frontend-deploy-without-ok`)。
## 独立 Taro 预览的用户授权例外
用户明确要求 Taro Web 的前端/后端/后台与各小程序独立。`apps/taro/web` 只连自己的 API(本地 10089)和后台(10088),不回落微信或门户生产服务。不能把 Next 门户的线上默认套到独立 Taro 项目;微信正式 API、数据和后台保持原样。