diff --git a/.talismanrc b/.talismanrc index 278b95a..b55b39e 100644 --- a/.talismanrc +++ b/.talismanrc @@ -239,7 +239,7 @@ fileignoreconfig: - "a project name passed on argv to the project resolver" - "expect\\(Object.keys\\(DEPENDENCIES\\)\\).toEqual\\(\\['project', 'env'\\]\\)" - filename: AGENTS.md - checksum: 3a255c9a11a4529ae420edc57565ef7e73355b83f3341c6ca7d21866ba0b2f8a + checksum: 86abf6589263684bab1a2e418764916059b59e95ac5e465c3820ecf8ac82be86 allowed_patterns: - "Do not add an exemption to a guard to make a new file pass" - "passes its own error wording to `client.request\\(req, MESSAGES\\)`" @@ -286,7 +286,7 @@ fileignoreconfig: - filename: test/integration/projects-list-command.test.ts checksum: 6709766943430b80aad2d7200102d936a92321e86c41f66d6a60a5baf82a81bf - filename: src/functions/cloud-functions.test.ts - checksum: db22822b030716145b386a08dfb647a7853d4981683858783c726c0cff3935e2 + checksum: 626305f8439f9b04652c287465e08ef681e9ae1eb3547313d5a8bbb5ff70a342 - filename: src/functions/function.errors.ts checksum: cad477cf24c97bf3395427235ca1de0f305369d05d61c21a83435654df2269e3 - filename: src/transport/proxy.test.ts diff --git a/AGENTS.md b/AGENTS.md index cc582c3..9be8fe8 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -535,6 +535,9 @@ The approved differences from V1 are these, and only these: `contentfly-deployment-agent`), as agreed with CL-8791's reporter. JSON and urlencoded bodies are parsed, `text/plain` arrives as the raw string, `application/octet-stream` as a Buffer, all up to Lambda's 6mb cap. `request.cookies` is the parsed `Cookie` header, or `{}`. + `request.query` also holds the path parameters, which win over a query value of the same name + (`/items/abc?id=zzz` → `{ id: 'abc' }`), as on AWS (CL-8970); Azure and GCP (V1) keep them only + in `request.params`. The project `.env` is loaded before the functions are bundled. Azure and GCP still run the vendored V1 server, which leaves text and octet-stream bodies unparsed; locally a handler that reads the raw request stream for those two types gets an empty stream. diff --git a/src/functions/cloud-functions.test.ts b/src/functions/cloud-functions.test.ts index a41228a..d980f51 100644 --- a/src/functions/cloud-functions.test.ts +++ b/src/functions/cloud-functions.test.ts @@ -308,6 +308,32 @@ describe('CloudFunctions serve routing', () => { expect(loggedLines).toContain(' λ /api/items/:id'); }); + it('adds path parameters to the query, as deployed functions do', async () => { + writeFunctionFile( + join('api', 'items', '[id].js'), + 'export default function item(request, response) { response.json({ query: request.query, params: request.params }); }', + ); + const port = await freePort(); + + await new CloudFunctions(workspace).serve(port); + const response = await sendRequest(port, '/api/items/abc?x=1'); + + expect(JSON.parse(response.body)).toEqual({ query: { x: '1', id: 'abc' }, params: { id: 'abc' } }); + }); + + it('lets a path parameter win over a query value of the same name, as deployed functions do', async () => { + writeFunctionFile( + join('api', 'items', '[id].js'), + 'export default function item(request, response) { response.json(request.query); }', + ); + const port = await freePort(); + + await new CloudFunctions(workspace).serve(port); + const response = await sendRequest(port, '/api/items/abc?id=zzz'); + + expect(JSON.parse(response.body)).toEqual({ id: 'abc' }); + }); + it('answers a post request on an exact route', async () => { writeFunctionFile('echo.js', 'export default function echo(request, response) { response.json({ method: request.method }); }'); const port = await freePort(); diff --git a/src/functions/cloud-functions.ts b/src/functions/cloud-functions.ts index 5df0578..f2d28ad 100755 --- a/src/functions/cloud-functions.ts +++ b/src/functions/cloud-functions.ts @@ -504,6 +504,7 @@ export class CloudFunctions { cloudFunctionResources.forEach((cloudFunctionResource) => { app.all(cloudFunctionResource.apiResourceURI, async (request: Request, response: Response) => { const answering = trackAnswering(request, response); + request.query = { ...request.query, ...request.params }; try { await cloudFunctionResource.handler(request, response); } catch (error) {