Skip to content

Commit ce0da81

Browse files
author
CodeBuddy Attribution Bot
committed
fix(attribution): HTTP 云函数 Skill 缺少路径映射和网关路径处理的关键说明 (issue_mo1hkx69_frhv2z)
1 parent 9765779 commit ce0da81

2 files changed

Lines changed: 48 additions & 1 deletion

File tree

config/source/skills/cloud-functions/SKILL.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
name: cloud-functions
33
description: CloudBase function runtime guide for building, deploying, and debugging your own Event Functions or HTTP Functions. This skill should be used when users need application runtime code on CloudBase, not when they are merely calling CloudBase official platform APIs.
4-
version: 2.18.0
4+
version: 2.18.1
55
alwaysApply: false
66
---
77

@@ -50,6 +50,7 @@ Keep local `references/...` paths for files that ship with the current skill dir
5050
- Confusing official CloudBase API client work with building your own HTTP function.
5151
- Mixing Event Function code shape (`exports.main(event, context)`) with HTTP Function code shape (`req` / `res` on port `9000`).
5252
- Treating HTTP Access as the implementation model for HTTP Functions. HTTP Access is a gateway configuration for Event Functions, not the HTTP Function runtime model.
53+
- Assuming the access path created by `manageGateway(action="createAccess")` is stripped before the request reaches an HTTP Function. It is not rewritten by default, so exposing `/api/http-demo` or the default `/${targetName}` changes the path your handler must match unless you normalize the prefix yourself.
5354
- Assuming `db.collection("name").add(...)` will create a missing document-database collection automatically. Collection creation is a separate management step.
5455
- Forgetting that runtime cannot be changed after creation.
5556
- Using cloud functions as the first answer for Web login.

config/source/skills/cloud-functions/references/http-functions.md

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,52 @@ Before enabling anonymous access, confirm both of these:
150150

151151
If an external caller reports `EXCEED_AUTHORITY`, inspect the function permission first with `queryPermissions(action="getResourcePermission", resourceType="function")` before widening access.
152152

153+
### Gateway path mapping for HTTP Functions
154+
155+
`manageGateway(action="createAccess")` creates a public access path, but it does **not** rewrite that path to `/` before the request reaches your HTTP Function.
156+
157+
- Public access path `/api/http-demo` + request `GET /api/http-demo` -> your server normally receives pathname `/api/http-demo`
158+
- Public access path `/api/http-demo` + request `GET /api/http-demo/health` -> your server normally receives pathname `/api/http-demo/health`
159+
- If you omit `path`, `createAccess` defaults to `/${targetName}`, so a handler that only matches `/` will not automatically match the default public URL
160+
161+
When your implementation wants internal routes like `/` and `/health`, use one of these approaches:
162+
163+
1. Match the public path directly in your handler.
164+
2. Strip a known public base path in code before routing.
165+
166+
Example with Node.js built-in `http` module:
167+
168+
```javascript
169+
const PUBLIC_BASE_PATH = process.env.PUBLIC_BASE_PATH || "";
170+
171+
function normalizePath(pathname) {
172+
if (!PUBLIC_BASE_PATH || PUBLIC_BASE_PATH === "/") {
173+
return pathname;
174+
}
175+
176+
if (pathname === PUBLIC_BASE_PATH) {
177+
return "/";
178+
}
179+
180+
if (pathname.startsWith(`${PUBLIC_BASE_PATH}/`)) {
181+
return pathname.slice(PUBLIC_BASE_PATH.length);
182+
}
183+
184+
return pathname;
185+
}
186+
187+
const server = http.createServer((req, res) => {
188+
const url = new URL(req.url, "http://127.0.0.1");
189+
const pathname = normalizePath(url.pathname);
190+
191+
if (req.method === "GET" && pathname === "/") {
192+
// Handle public /api/http-demo as internal /
193+
}
194+
});
195+
```
196+
197+
Do not assume `createAccess` gives you gateway rewrite behavior. If you need separate route-rewrite semantics, treat that as an explicit gateway-routing requirement and confirm the route capability first instead of guessing.
198+
153199
## SSE and WebSocket notes
154200

155201
### SSE

0 commit comments

Comments
 (0)