Skip to content

Commit 155bca2

Browse files
authored
Merge pull request #530 from TencentCloudBase/feature/attribution-http-functions-express5-wildcard
fix: Express 5 wildcard HTTP function reference
2 parents efad80b + 69dff5f commit 155bca2

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,13 +76,15 @@ app.post("/users", (req, res) => {
7676
return res.status(201).json({ name, email });
7777
});
7878

79-
app.all("*", (req, res) => {
79+
app.all("/{*splat}", (req, res) => {
8080
res.status(405).json({ error: "Method Not Allowed" });
8181
});
8282

8383
app.listen(9000);
8484
```
8585

86+
Express 5 note: do not use bare `*` or `/*` here. Express 5 uses `path-to-regexp` with named wildcards, so `app.all("/{*splat}", ...)` is the safe catch-all form when you also need to match the root path `/`.
87+
8688
## Deployment flow
8789

8890
Prefer `manageFunctions` over CLI in agent flows.

tests/skill-quality-standards.test.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,23 @@ describe('skill quality standards', () => {
6565
expect(raw).toMatch(/cost/i);
6666
});
6767

68+
test('cloud-functions http reference stays compatible with Express 5 wildcard syntax', () => {
69+
const raw = readFile(
70+
'config',
71+
'source',
72+
'skills',
73+
'cloud-functions',
74+
'references',
75+
'http-functions.md',
76+
);
77+
78+
expect(raw).not.toContain('app.all("*")');
79+
expect(raw).not.toContain("app.all('/*')");
80+
expect(raw).toContain('app.all("/{*splat}", (req, res) => {');
81+
expect(raw).toMatch(/Express 5 note:/);
82+
expect(raw).toMatch(/path-to-regexp/);
83+
});
84+
6885
test('cloudbase-agent does not force global activation by default', () => {
6986
const raw = readSourceSkill('cloudbase-agent');
7087

0 commit comments

Comments
 (0)