-
Notifications
You must be signed in to change notification settings - Fork 509
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(netlify, aws): omit cookies from v1 response (#834)
* fix(aws-lambda): omit cookies from v1 response * feat: use overloads to improve type safety * chore: lint * fix: netlify builder function should share netlify lambda implementation * fix: don't strip `set-cookie` with v1 payload * fix(netlify): don't strip `set-cookie` headers
- Loading branch information
Showing
4 changed files
with
94 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { builder } from "@netlify/functions"; | ||
import { handler as _handler } from "#internal/nitro/entries/aws-lambda"; | ||
import { lambda } from "./netlify-lambda"; | ||
|
||
export const handler = builder(_handler); | ||
export const handler = builder(lambda); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
import "#internal/nitro/virtual/polyfill"; | ||
import type { | ||
Handler, | ||
HandlerResponse, | ||
HandlerContext, | ||
HandlerEvent, | ||
} from "@netlify/functions/dist/main"; | ||
import type { APIGatewayProxyEventHeaders } from "aws-lambda"; | ||
import { withQuery } from "ufo"; | ||
import { nitroApp } from "../app"; | ||
|
||
export async function lambda( | ||
event: HandlerEvent, | ||
context: HandlerContext | ||
): Promise<HandlerResponse> { | ||
const query = { | ||
...event.queryStringParameters, | ||
...event.multiValueQueryStringParameters, | ||
}; | ||
const url = withQuery(event.path, query); | ||
const method = event.httpMethod || "get"; | ||
|
||
const r = await nitroApp.localCall({ | ||
event, | ||
url, | ||
context, | ||
headers: normalizeIncomingHeaders(event.headers), | ||
method, | ||
query, | ||
body: event.body, // TODO: handle event.isBase64Encoded | ||
}); | ||
|
||
return { | ||
statusCode: r.status, | ||
headers: normalizeOutgoingHeaders(r.headers), | ||
body: r.body.toString(), | ||
}; | ||
} | ||
|
||
function normalizeIncomingHeaders(headers?: APIGatewayProxyEventHeaders) { | ||
return Object.fromEntries( | ||
Object.entries(headers || {}).map(([key, value]) => [ | ||
key.toLowerCase(), | ||
value!, | ||
]) | ||
); | ||
} | ||
|
||
function normalizeOutgoingHeaders( | ||
headers: Record<string, string | string[] | undefined> | ||
) { | ||
return Object.fromEntries( | ||
Object.entries(headers).map(([k, v]) => [ | ||
k, | ||
Array.isArray(v) ? v.join(",") : v!, | ||
]) | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters