Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .talismanrc
Original file line number Diff line number Diff line change
Expand Up @@ -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\\)`"
Expand Down Expand Up @@ -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
Expand Down
3 changes: 3 additions & 0 deletions AGENTS.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
26 changes: 26 additions & 0 deletions src/functions/cloud-functions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/functions/cloud-functions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Loading