这是个测试灯。应在何处指定格式?middy现在是否需要在某个地方指定event.requestContext.http.method?
import 'source-map-support/register';
import type { ValidatedEventAPIGatewayProxyEvent } from '@libs/apiGateway';
import { formatJSONResponse } from '@libs/apiGateway';
import { middyfy } from '@libs/lambda';
import schema from './schema';
const hello: ValidatedEventAPIGatewayProxyEvent<typeof schema> = async (event) => {
return formatJSONResponse({
headers: {
'Access-Control-Allow-Origin': '*',
'Access-Control-Allow-Credentials': true,
},
message: `Hello ${event.body.name}, welcome to the exciting Serverless world!`,
event,
});
}
export const main = middyfy(hello);环境是
"@middy/core": "^3.1.0",
"@middy/http-cors": "^3.1.0",使用无服务器:框架核心: 3.21.0 (本地) 3.21.0 (全局)
执行是通过
无服务器调用本地--函数hello --路径src/function/hello/mock.json
"errorMessage": "[http-cors] Unknown http event format",
"errorType": "Error",
"stackTrace": [
"Error: [http-cors] Unknown http event format",
" at httpCorsMiddlewareAfter (/Users/jrobens/NetBeansProjects/azuron/winpay/winpay-admin-api/node_modules/@middy/http-cors/index.cjs:82:19)",发布于 2022-08-13 04:29:07
@middy/ HTTP -cors支持REST (v1)和HTTP (v2) AWS事件。您的测试事件并不完全符合HTTP (v2) AWS事件结构。让它包含event.requestContext.http.method将解决这个问题。AWS文档中的示例:https://docs.aws.amazon.com/lambda/latest/dg/services-apigateway.html。
https://stackoverflow.com/questions/73203199
复制相似问题