fix(nitro): handle incoming cookies on lambda payload format 2.0 (#3136)

This commit is contained in:
Daniel Roe 2022-02-09 11:50:57 +00:00 committed by GitHub
parent 7825e2aa12
commit 569aaeb314
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -1,12 +1,16 @@
import type { APIGatewayProxyEvent, APIGatewayProxyEventHeaders, APIGatewayProxyEventV2, Context } from 'aws-lambda'
import type { APIGatewayProxyEvent, APIGatewayProxyEventHeaders, APIGatewayProxyEventV2, APIGatewayProxyResult, APIGatewayProxyResultV2, Context } from 'aws-lambda'
import '#polyfill'
import { withQuery } from 'ufo'
import type { HeadersObject } from 'unenv/runtime/_internal/types'
import { localCall } from '../server'
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'
export const handler = async function handler (event: APIGatewayProxyEvent | APIGatewayProxyEventV2, context: Context): Promise<APIGatewayProxyResult | APIGatewayProxyResultV2> {
const url = withQuery((event as APIGatewayProxyEvent).path || (event as APIGatewayProxyEventV2).rawPath, event.queryStringParameters)
const method = (event as APIGatewayProxyEvent).httpMethod || (event as APIGatewayProxyEventV2).requestContext?.http?.method || 'get'
if ('cookies' in event) {
event.headers.cookie = event.cookies.join(',')
}
const r = await localCall({
event,
@ -26,7 +30,7 @@ export const handler = async function handler (event: APIGatewayProxyEvent & API
}
function normalizeIncomingHeaders (headers: APIGatewayProxyEventHeaders) {
return Object.fromEntries(Object.entries(headers).map(([key, value]) => [key.toLowerCase(), value as string]))
return Object.fromEntries(Object.entries(headers).map(([key, value]) => [key.toLowerCase(), value]))
}
function normalizeOutgoingHeaders (headers: HeadersObject) {