DenisFrezzato / hyper-ts

Type safe middleware architecture for HTTP servers
https://denisfrezzato.github.io/hyper-ts/
MIT License
391 stars 18 forks source link

Support AWS-Lambda #28

Closed lujiajing1126 closed 3 years ago

lujiajing1126 commented 4 years ago

This PR contains support for aws lambda.

The main idea essentially follows the express connection. But since the handlers used in aws-lambda are not organized like a stack, the semantics of nextFunction and ended should be changed in this case.

Besides, the original interface requires the implementations to return http.IncomingMessage as request, I don't think it is reasonable, since other framework like koajs wraps its own request object. So I change this to unknown just like other methods.

Other misc improvements:

DenisFrezzato commented 4 years ago

I'm confused. A serverless function is invoked at some event (like an HTTP request, handled from API Gateway). A framework like hyper-ts is meant to run and listen for incoming HTTP requests. Why would you like to instantiate an HTTP server inside a serverless function which is going to be instantiated every time the function is invoked and die as soon as the response is sent? It sounds like a redundant thing to do. What would be the benefits and what problem are you trying to solve?

lujiajing1126 commented 4 years ago

As I understand, this framework is not designed to be responsible for accepting/listening low level http sockets, but to provide a design pattern to orgranize stacked middlewares, which may represent different stages of request handling. Sure, the type-safety itself would automatically guarantee the correct order of composing the middlewares. So I think it is not releated to "instantiate an HTTP server", express or koajs would do that for you! It is about processing the "event" in a correct way, i.e. an HTTP request in regular case and APIGatewayProxyEvent for aws-lambda. Besides, error handling, request body consuming, authentication and authorization are also common use cases for aws lambda. Using together with io-ts would helpful for this purpose.

DenisFrezzato commented 3 years ago

@lujiajing1126 thank you for your contribution (and sorry for the late reply) but I'd like to keep this package as lean as possible. Feel free to create this adapter on a package of its own, just like hyper-ts-connect or hyper-ts-fastify.

lujiajing1126 commented 3 years ago

@lujiajing1126 thank you for your contribution (and sorry for the late reply) but I'd like to keep this package as lean as possible. Feel free to create this adapter on a package of its own, just like hyper-ts-connect or hyper-ts-fastify.

I see. Grazie!