Open effect-bot opened 2 months ago
when using SST Ion and calling HttpApp.toWebHandler
the following error pops
Cannot read properties of undefined (reading 'addEventListener')
It points to request.signal.addEventListener("abort", ...)
the issue is that in aws lambdas the fetch API spec is not complete meaning that the Request
is missing AbortController
api support, the kind that would give it the .signal
property.
Supposedly aws lambda support it in their nodejs 18 lambdas
but according to everyone else besides aws thats not true and you must add /* global fetch */
to the start of the file, but even then it seems that it's not enough and it does not make AbortController
and AbortSignal
available
There is a suggested polyfill but it won't help us because the the Request
is coming straight from the lambda
Well, calling it a platform bug is quite a stretch given it's AWS that is not spec-compliant. BTW make sure comments are not removed in the build pipeline, otherwise /* global fetch */
has no effect
@mikearnaldi Ah, I am not the one impacted lol
I think it's a bug because it breaks in /platform
, not /platform-node
or something.. In general Request
is not a platform-agnostic concept. node can't produce a server that speaks in Request
and Response
for example. It only knows IncomingMessage
and OutgoingMessage
which also have different semantics (for the node-native http
and https
they inverse at the boundaries, you send OutgoingMessage
and receive it as an IncomingMessage
, send back an OutgoingMessage
and it arrives as an IncomingMessage
), It can be 'fixed' (mitigated) with a simple check for the existence of the signal.
Not fixing this means that even if we were to release a theoretical /platform-aws
, it'll be inoperable unless it ships it's own AwsHttpApp.toWebHandler
cc @tim-smart
Summary
Summary
The conversation revolves around implementing an AWS Lambda function using
effect-http
, similar to how it's done with thehono
framework. The user aims to create a "fat lambda" that handles all requests. Here's a summary of the key points and takeaways:Initial Inquiry:
effect-http
, similar to thehono
example provided.Community Input:
effect-aws
and@effect/platform
for potential solutions.toWebHandler
function from@effect/platform
was suggested as a possible solution.Code Examples:
HttpApp.toWebHandler
andHttpApp.toWebHandlerLayer
to create the handler.HttpApp.toWebHandlerLayer
for performance reasons was highlighted.Issues Encountered:
addEventListener
and missing files (ENOENT
).Root Cause Analysis:
Request
object missing theAbortController
API support.AbortController
.Potential Solutions:
/* global fetch */
to the start of the file was suggested but deemed insufficient.AbortController
was considered but might not resolve the issue since theRequest
object comes from AWS.Key Takeaways
Compatibility Issues:
AbortController
andAbortSignal
.Performance Considerations:
HttpApp.toWebHandlerLayer
to avoid performance issues related to reading files from disk on every request.Error Handling:
Community Support:
effect-http
project is community-driven, and solutions may require collaboration and experimentation.Documentation and Examples:
effect-http
with AWS Lambda, indicating a need for more community contributions and shared knowledge.By addressing these key points, the user can better navigate the challenges of implementing
effect-http
with AWS Lambda and potentially contribute to the community's knowledge base.Discord thread
https://discord.com/channels/795981131316985866/1256526365008728097