Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Cloudflareを使い倒す!

totto2727
September 05, 2024

 Cloudflareを使い倒す!

totto2727

September 05, 2024
Tweet

More Decks by totto2727

Other Decks in Programming

Transcript

  1. 他にも Cloudflare Workers Cloudflare D1 Cloudflare KV Cloudflare Queues Cron

    Triggers Workers AI Cloudflare R2 Cloudflare Zero Trust etc... 5
  2. 7

  3. 作成中のRSS Reader RPC バックエンド Cloudflare D1 Cron RSS FeedのTrigger Queue

    取得処理のバファー Pages Webフロントエンド RSS Feedの取得処理 外部に公開しない処理 ユーザー RSS Feed (Zennなど) 11
  4. RPCモードのサンプルコード // worker1.ts import { WorkerEntrypoint } from "cloudflare:workers"; export

    default class extends WorkerEntrypoint { async fetch() { return new Response("Hello World"); } async newCounter() { let value = 0; return (increment = 0) => { value += increment; return value; }; } } # worker2 > wrangler.toml name = "client_worker" main = "./src/clientWorker.js" services = [ { binding = "COUNTER_SERVICE", service = "counter-service" } ] // worker2.ts export default { async fetch(request, env) { using f = await env.COUNTER_SERVICE.newCounter(); await f(2); // returns 2 await f(1); // returns 3 const count = await f(-5); // returns -2 return new Response(count); }, }; 13