Closed lujiajing1126 closed 3 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?
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.
@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 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!
This PR contains support for aws lambda.
The main idea essentially follows the
express
connection. But since the handlers used inaws-lambda
are not organized like a stack, the semantics ofnextFunction
andended
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 likekoajs
wraps its own request object. So I change this tounknown
just like other methods.Other misc improvements:
prepublish
toprepare
as suggested bynpm@5
inpackage.json
fp-ts
to dependency