transloadit / node-sdk

Transloadit's official Node.js SDK
https://transloadit.com
MIT License
62 stars 26 forks source link

Improvements #89

Open mifi opened 3 years ago

mifi commented 3 years ago

Potential improvements discovered during #87 but not blocking its merge:

Logs / Global Event Emitter

Could allow the user subscribe to:

If we decide to add an EventEmitter it could lead to breaking changes (e.g. removing onUploadProgress and onAssemblyProgress from method options and move them to event listener)

Tests improvements

mifi commented 3 years ago

localtunnel is down, causing github actions to fail. I think we should find a better solution https://github.com/transloadit/node-sdk/runs/2021853285?check_suite_focus=true

kvz commented 3 years ago

As per our docs https://transloadit.com/docs/ we could use ngrok which has a business (model) behind it, but allows limited free use(?)

mifi commented 3 years ago

Turns out ngrok doesn't work for requests coming from services hosted on AWS, so we should update our docs at https://transloadit.com/docs/ also to instead use localtunnel or something else. Or maybe we can host our own similar tunnelling service (possibly with a whitelist from transloadit IP ranges).

https://github.com/inconshreveable/ngrok/issues/408

kvz commented 3 years ago

Or maybe we can host our own similar tunneling service (possibly with a whitelist from transloadit IP ranges)

I like this idea.. It could maybe even work agnostically/transparently for a few SDKs if we build in support for that :thinking:

(for now i am leaving a comment in our docs as well)

mifi commented 2 years ago

so localtunnel seems to be down most of the time and causing a lot of failed builds recently.

there's a myriad of different open source proxies we could set up and run, but we would have to set up and maintain a server.

there's also cloudflare that seems to support this as a service. which solution should we go for?

kvz commented 2 years ago

We could ask @calbrecht to set up an ngrok service on our us-east-1 observer on maybe? https://github.com/inconshreveable/ngrok/blob/master/docs/SELFHOSTING.md any security implications with that?

we could host it on ngrok.transloadit.net. or can it not be hosted on a subdomain?

kvz commented 2 years ago

You know what, if Cloudflare can solve the problem immediately, let's use that first, and consider selfhosting an upgrade after that for which we can then reserve more time?

mifi commented 2 years ago

I found something new called Cloudflare Quick Tunnels: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps/run-tunnel/trycloudflare It means we can create these "demo" tunnels with the cloudflared cli, without any configuration or dns (or even authentication!) So I will try this first and see if it works ebef58b8ddbf338e6ece1e7b9f0a4850ae2ab4b1

mifi commented 2 years ago

Have now replaced localtunnel with cloudflare quick tunnels #143. The cloudflared CLI is a bit lacking quality: It doesn't report when the tunnel is actually ready, so I needed to

  1. do a regex on its stderr to find the URL
  2. poll a DNS query of the hostname until it's ready using node.js resolve4 api (not using the operating system's lookup, as it will poison the dns cache).
  3. poll a HTTP request through the tunnel in order to know that the tunnel is "healthy" before we can use it in our tests.

After a lot of obscure issues I have finally managed to work this all out, so it works now! for those curious, the logic is in https://github.com/transloadit/node-sdk/blob/master/test/testserver.js and https://github.com/transloadit/node-sdk/blob/master/test/tunnel.js

Note that when cloudflared starts up it prints:

line 2022-08-01T17:34:37Z INF Thank you for trying Cloudflare Tunnel. Doing so, without a Cloudflare account, is a quick way to experiment and try it out. However, be aware that these account-less Tunnels have no uptime guarantee. If you intend to use Tunnels in production you should use a pre-created named tunnel by following: https://developers.cloudflare.com/cloudflare-one/connections/connect-apps

So it's not for production, but for our tests it should work, unless they start blocking Github actions' IPs. If they do that, we can go ahead and setup the private tunnels instead, and that shouldn't be too much work because they also use the same cloudflared CLI.