dbartholomae / lambda-middleware

A collection of middleware for AWS lambda functions.
https://dbartholomae.github.io/lambda-middleware/
MIT License
152 stars 18 forks source link

Compatibility with Http API #74

Closed pareis closed 10 months ago

pareis commented 1 year ago

At the moment, cors middleware seems to not support a version 2.0 payload of the HTTP API for AWS Lambda. There, the HTTP method is available under event.requestContext.http.method not event.httpMethod.

Here's the existing code:

    if (event.httpMethod.toLowerCase() === "options") {
      return handlePreflightRequest(runHandler, event, fullOptions);
    }

Would you be willing to help with a PR?

Describe the solution you'd like

The handler should be able to dynamically understand an HTTP API payload.

Describe alternatives you've considered

I have removed the dedicated middleware config for the APIs in question and have instead set cors to true at the API Gateway level. This works in my case but will not allow fine grained control that might be needed for sophisticated cases.

Additional context

None

dbartholomae commented 1 year ago

Thanks! What would you hope to get from a CORS middleware compared to the built-in CORS functionality in HTTP APIs? https://docs.aws.amazon.com/apigateway/latest/developerguide/http-api-cors.html

Not saying that there isn't a use case, just trying to better understand the situation.

dbartholomae commented 10 months ago

Closed as there was no response