This repository has been archived by the owner on Apr 6, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nitro): add support for lambda v2 payload format (#3070)
Co-authored-by: Pooya Parsa <pyapar@gmail.com>
- Loading branch information
Showing
5 changed files
with
65 additions
and
8 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
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,21 +1,34 @@ | ||
import type { APIGatewayProxyEvent, APIGatewayProxyEventHeaders, APIGatewayProxyEventV2, Context } from 'aws-lambda' | ||
import '#polyfill' | ||
import { withQuery } from 'ufo' | ||
import type { HeadersObject } from 'unenv/runtime/_internal/types' | ||
import { localCall } from '../server' | ||
|
||
export async function handler (event, context) { | ||
export const handler = async function handler (event: APIGatewayProxyEvent & APIGatewayProxyEventV2, context: Context) { | ||
const url = withQuery(event.path || event.rawPath, event.queryStringParameters) | ||
const method = event.httpMethod || event.requestContext?.http?.method || 'get' | ||
|
||
const r = await localCall({ | ||
event, | ||
url: withQuery(event.path, event.queryStringParameters), | ||
url, | ||
context, | ||
headers: event.headers, | ||
method: event.httpMethod, | ||
headers: normalizeIncomingHeaders(event.headers), | ||
method, | ||
query: event.queryStringParameters, | ||
body: event.body // TODO: handle event.isBase64Encoded | ||
}) | ||
|
||
return { | ||
statusCode: r.status, | ||
headers: r.headers, | ||
headers: normalizeOutgoingHeaders(r.headers), | ||
body: r.body.toString() | ||
} | ||
} | ||
|
||
function normalizeIncomingHeaders (headers: APIGatewayProxyEventHeaders) { | ||
return Object.fromEntries(Object.entries(headers).map(([key, value]) => [key.toLowerCase(), value as string])) | ||
} | ||
|
||
function normalizeOutgoingHeaders (headers: HeadersObject) { | ||
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
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