dbartholomae / lambda-middleware

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

Compatibility with Http API #74

Closed pareis closed 8 months ago

pareis commented 10 months 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 10 months 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 8 months ago

Closed as there was no response