Skip to content

feat(api): expose protocol and host on lambda fastify requests#1654

Merged
Tobbe merged 2 commits intocedarjs:mainfrom
mgramigna:mg/expose-more-request-context
Apr 22, 2026
Merged

feat(api): expose protocol and host on lambda fastify requests#1654
Tobbe merged 2 commits intocedarjs:mainfrom
mgramigna:mg/expose-more-request-context

Conversation

@mgramigna
Copy link
Copy Markdown
Contributor

We have a use case where we need to re-construct a url in our lambda handler based on the event.

In a typical lambda handler, these properties are expected to be there, but cedar appears to not be mapping all required properties from the fastify request. We just need these ones, but worth considering if we should be trying to map more. This is the expected type from aws lambda:

export interface APIGatewayProxyEventBase<TAuthorizerContext> {
    body: string | null;
    headers: APIGatewayProxyEventHeaders;
    multiValueHeaders: APIGatewayProxyEventMultiValueHeaders;
    httpMethod: string;
    isBase64Encoded: boolean;
    path: string;
    pathParameters: APIGatewayProxyEventPathParameters | null;
    queryStringParameters: APIGatewayProxyEventQueryStringParameters | null;
    multiValueQueryStringParameters: APIGatewayProxyEventMultiValueQueryStringParameters | null;
    stageVariables: APIGatewayProxyEventStageVariables | null;
    requestContext: APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext>;
    resource: string;
}

export interface APIGatewayEventRequestContextWithAuthorizer<TAuthorizerContext> {
    accountId: string;
    apiId: string;
    authorizer: TAuthorizerContext;
    connectedAt?: number | undefined;
    connectionId?: string | undefined;
    domainName?: string | undefined;
    domainPrefix?: string | undefined;
    eventType?: string | undefined;
    extendedRequestId?: string | undefined;
    protocol: string;
    httpMethod: string;
    identity: APIGatewayEventIdentity;
    messageDirection?: string | undefined;
    messageId?: string | null | undefined;
    path: string;
    stage: string;
    requestId: string;
    requestTime?: string | undefined;
    requestTimeEpoch: number;
    resourceId: string;
    resourcePath: string;
    routeKey?: string | undefined;
}

@netlify
Copy link
Copy Markdown

netlify Bot commented Apr 21, 2026

👷 Deploy request for cedarjs pending review.

Visit the deploys page to approve it

Name Link
🔨 Latest commit 06277e9

@github-actions github-actions Bot added this to the chore milestone Apr 21, 2026
@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 21, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 06277e9

Command Status Duration Result
nx run-many -t build:pack --exclude create-ceda... ✅ Succeeded 6s View ↗
nx run-many -t build ✅ Succeeded 4s View ↗
nx run-many -t test --minWorkers=1 --maxWorkers=4 ✅ Succeeded 1m 18s View ↗
nx run-many -t test:types ✅ Succeeded 7s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-22 15:02:16 UTC

@nx-cloud
Copy link
Copy Markdown

nx-cloud Bot commented Apr 21, 2026

🤖 Nx Cloud AI Fix

Ensure the fix-ci command is configured to always run in your CI pipeline to get automatic fixes in future runs. For more information, please see https://nx.dev/ci/features/self-healing-ci


View your CI Pipeline Execution ↗ for commit 2b27dea

Command Status Duration Result
nx run-many -t build ✅ Succeeded 14s View ↗

☁️ Nx Cloud last updated this comment at 2026-04-21 21:28:31 UTC

@Tobbe
Copy link
Copy Markdown
Member

Tobbe commented Apr 21, 2026

Thanks for the PR Matt.

Since you're touching this area of the code I also wanted to make you aware of this: #1616

@mgramigna
Copy link
Copy Markdown
Contributor Author

Thanks for the PR Matt.

Since you're touching this area of the code I also wanted to make you aware of this: #1616

Oh sweet, this might not be necessary then if you're moving to a standardized approach. We can probably work around it for now, feel free to close

@Tobbe
Copy link
Copy Markdown
Member

Tobbe commented Apr 21, 2026

We can probably work around it for now, feel free to close

It's such a small change I'll merge it as soon as CI passes. Also gives me a good reason to get a new release of Cedar out :)

@Tobbe Tobbe mentioned this pull request Apr 21, 2026
@greptile-apps
Copy link
Copy Markdown
Contributor

greptile-apps Bot commented Apr 21, 2026

Greptile Summary

This PR updates lambdaEventForFastifyRequest to inject x-forwarded-proto from request.protocol as a default header (allowing upstream headers to override it), and adds requestContext.domainName from request.hostname. The implementation correctly addresses the previous review thread's feedback about requestContext.protocol semantic mismatch, and the new tests verify both the fallback and precedence behaviours. The project overview doc remains accurate — no architectural details are affected by this change.

Confidence Score: 5/5

Safe to merge — the change is well-scoped, properly tested, and resolves the prior review feedback.

No P0 or P1 findings. The spread order correctly lets existing upstream headers override the x-forwarded-proto default, which is verified by the new tests. The domainName mapping is a straightforward addition with no correctness concerns.

No files require special attention.

Important Files Changed

Filename Overview
packages/api-server/src/requestHandlers/awsLambdaFastify.ts Injects x-forwarded-proto from request.protocol as a fallback header (upstream headers take precedence), and maps request.hostname to requestContext.domainName — both addressing the prior review thread's feedback.
packages/api-server/src/tests/requestHandlers/awsLambdaFastify.test.ts Adds a new test suite for lambdaEventForFastifyRequest covering both the absent-header case (protocol fallback) and the header-precedence case (upstream x-forwarded-proto wins), with correct assertions.

Reviews (3): Last reviewed commit: "fix: use x-forwarded-proto, respecting h..." | Re-trigger Greptile

Comment thread packages/api-server/src/requestHandlers/awsLambdaFastify.ts Outdated
@mgramigna mgramigna force-pushed the mg/expose-more-request-context branch from e98e3ae to 06277e9 Compare April 22, 2026 14:38
@mgramigna
Copy link
Copy Markdown
Contributor Author

mgramigna commented Apr 22, 2026

@greptileai re-review the PR

@Tobbe Tobbe changed the title chore(api): expose protocol and host on lambda fastify requests fix(api): expose protocol and host on lambda fastify requests Apr 22, 2026
@Tobbe Tobbe modified the milestones: chore, next-release-patch Apr 22, 2026
@Tobbe Tobbe changed the title fix(api): expose protocol and host on lambda fastify requests feat(api): expose protocol and host on lambda fastify requests Apr 22, 2026
@Tobbe Tobbe enabled auto-merge (squash) April 22, 2026 16:14
@Tobbe Tobbe merged commit 49d4e1d into cedarjs:main Apr 22, 2026
53 of 57 checks passed
@Tobbe Tobbe modified the milestones: next-release, v4.1.0 Apr 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants