silvia-odwyer / photon

⚡ Rust/WebAssembly image processing library
https://silvia-odwyer.github.io/photon
Apache License 2.0
2.69k stars 151 forks source link

Cloudflare Workers Tutorial Boilerplate WASM WASI #138

Open dtruffaut opened 2 years ago

dtruffaut commented 2 years ago

Cloudflare Workers is a popular serverless platform. A tutorial + boilerplate explaining how to setup Photon would be awesome.

Cloudflare Workers supports Photon

Demo https://image-demo.denoflare.dev/ https://denoflare.dev/examples/transform-images-wasm Code https://github.com/skymethod/denoflare/blob/v0.5.8/examples/image-demo-worker/img.ts https://github.com/skymethod/denoflare/blob/9e01b76e6569653c7092a9ab3280e190e146300b/common/import_wasm.ts

Cloudflare Workers supports WASI

Native: https://blog.cloudflare.com/running-zig-with-wasi-on-cloudflare-workers/ Javascript: https://blog.cloudflare.com/announcing-wasi-on-workers/ (Preferred) cargo build --target wasm32-wasi --release

Cloudflare Workers supports Fetch

No need for node-fetch, you can fetch directly in Cloudflare Workers const response = await fetch(url, init);

init is basically the request options plus some Cloudflare extra parameters if needed. https://developers.cloudflare.com/workers//runtime-apis/request#requestinit

--

Reducing the deployment friction with a tutorial would facilitate the web developers adoption. This is an opportunity to make Photon super popular.

Thanks :)

silvia-odwyer commented 2 years ago

@dtruffaut Hi Denis, Wow, thank you very much for this! I had a look at the Denoflare demo you linked, and was very impressed by it overall. Cloudflare's WASI support is a very exciting development in the space, and I'm so impressed by Cloudflare Workers' incredible performance! I'll definitely have to set up Photon with Cloudflare Workers in the near future and post a tutorial on it also.

I'll also link to the Denoflare demo in the README of this repo also, so that others can see Photon and Cloudflare Workers in action 🎉

Thanks again!

saibotrellum commented 1 year ago

I'll definitely have to set up Photon with Cloudflare Workers in the near future and post a tutorial on it also.

That would be awesome! Sadly I can't find an example using Photon on Cloudflare without Deno. And a quick read-through of the the Demo code above shows several Deno-specific changes + several includes that seems to hold code for other Demos in this repository. So testing what is (not) needed without Deno or other demo modules is not a quick job (for me, at least :-).

So a short example of how to run on CF without Deno would be greatly appreciated. No need to be as extensive, just some code example with one working image manipulation would already be a huge help.

Thanks!

ccbikai commented 10 months ago

I'll definitely have to set up Photon with Cloudflare Workers in the near future and post a tutorial on it also.

That would be awesome! Sadly I can't find an example using Photon on Cloudflare without Deno. And a quick read-through of the the Demo code above shows several Deno-specific changes + several includes that seems to hold code for other Demos in this repository. So testing what is (not) needed without Deno or other demo modules is not a quick job (for me, at least :-).

So a short example of how to run on CF without Deno would be greatly appreciated. No need to be as extensive, just some code example with one working image manipulation would already be a huge help.

Thanks!

look here https://github.com/ccbikai/cloudflare-worker-image