`"use node";` in HTTP actions
I just used
sharp
(https://github.com/lovell/sharp) to build an HTTP action which accepts a storage ID and a desired width and height (as search params), and returns a dynamically-sized image. The HTTP action works pretty well, but since sharp
needs to be bundled as an external package, it only works in the Node runtime, which isn't available for HTTP actions. So I have to instead call out to another, separate action, which does the actual transforming, and then do some munging to get the image encoded as a base64 string (in order to return it to the HTTP action), and then returned as a proper image in the HTTP action's response (which means, I think, that it needs to become a Blob
once more).
My questions:
1. Why don't HTTP actions support the Node environment? Could they?
2. Given the current limitations, any suggestions for how I might improve this setup?1 Reply
Hey @RJ, your approach is correct, one suggestion for improvement perhaps is to try to return the image as Bytes (via ArrayBuffer). This will do the encoding for you.