linux_china技术雷达linux_china技术雷达

Cloudflare Workers & Pages

serverless
采用

Cloudflare Workers & Pages 是一个基于 Cloudflare 的无服务器平台,它提供了一个简单、快速、安全的方式来构建和部署 Web 应用、网站等。

Cloudflare Workers Runtime API主要如下:

  • Bindings (env): Worker Bindings that allow for interaction with other Cloudflare Resources.
  • Cache: Control reading and writing from the Cloudflare global network cache.
  • Console: Supported methods of the console API in Cloudflare Workers
  • Context (ctx): The Context API in Cloudflare Workers, including waitUntil and passThroughOnException.
  • Encoding: Takes a stream of code points as input and emits a stream of bytes.
  • Fetch: An interface for asynchronously fetching resources via HTTP requests inside of a Worker.
  • Handlers: Methods, such as fetch(), on Workers that can receive and process external inputs.
  • Headers: Access HTTP request and response headers.
  • HTMLRewriter: Build comprehensive and expressive HTML parsers inside of a Worker application.
  • Node.js compatibility: Implemented Node.js runtime APIs and enablement instructions for your Worker project.
  • Performance and timers: Measure timing, performance, and timing of subrequests and other operations.
  • Remote-procedure call (RPC): The built-in, JavaScript-native RPC system built into Workers and Durable Objects.
  • Request: Interface that represents an HTTP request.
  • Response: Interface that represents an HTTP response.
  • Streams: A web standard API that allows JavaScript to programmatically access and process streams of data.
  • TCP sockets: Use the connect() API to create outbound TCP connections from Workers.
  • Web Crypto: A set of low-level functions for common cryptographic tasks.
  • Web standards: Standardized APIs for use by Workers running on Cloudflare's global network.
  • WebAssembly (Wasm): Execute code written in a language other than JavaScript or write an entire Cloudflare Worker in Rust.
  • WebSockets: Communicate in real time with your Cloudflare Workers.

Cloudflare Workers除了本身是JS/Wasm引擎外和Runtime API外,Cloudflare还为其提供了其他额外特性,方便开发者构建更多类型的应用,例如:

  • KV存储
  • Workers AI
  • R2:对象存储
  • D1:关系型数据库
  • Durable Objects:带状态管理的组件
  • Queues
  • Vectorize

注意: 如果你要Cloudflare Workers使用第三方package,最好通过 https://jsr.io/ 进行查询,有对应的Cloudflare Workers兼容提示。

Cloudflare Workers & Friends

References