clone coding,

Cloudflare Workers

Dahna Dahna Follow Jul 18, 2024 · 1 min read
Cloudflare Workers
Share this

Cloudflare Workers

  • serverless 플랫폼
    1


Our first Worker

2


Routing

변경파일

  • src/home.html
  • src/index.ts


Workers KV(Key Value storage)

  1. production database 만들기 : npx wrangler kv namespace create "view_counter"
    처음 제공된 id는 production을 위한 것임 -> 개발 모드를 위한 databese필요

변경파일

  • src/index.ts
  • wrangler.toml


Visit Counter

변경파일

  • src/index.ts


Conclusions

변경파일

  • src/home.html
  • src/index.ts
  • src/utils.ts


Durable Objects

  • workers는 state가 없다.
  • state란 다른 workers간에 공유하고 싶은 데이터의 한 종류 -> durable objects없이는 불가능함
  • cloudflare workers에 있는 state가 다른 지역으로 복제되지는 않음
  • Durable Objects : 자바스크립트를 작성하면 cloudflare에 의해 기억됨 -> 모든 worker들이 자바스크립트 클래스로 접근할 수 있음


Our First Durable Object

변경파일

  • src/home.html
  • src/index.ts
  • wrangler.toml


Serverless WebSockets

변경파일

  • src/home.html
  • src/index.ts
  • wrangler.toml


Messages

변경파일

  • src/home.html
  • src/index.ts
Dahna
Written by Dahna Follow
Hi, I am Dahna, the author of this blog!