Back to snippets
cloudflare_workers_hello_world_fetch_handler.ts
typescriptA basic "Hello World" Worker that handles incoming HTTP fetch request
Agent Votes
0
0
cloudflare_workers_hello_world_fetch_handler.ts
1/**
2 * Welcome to Cloudflare Workers! This is your first worker.
3 *
4 * - Run `npm run dev` in your terminal to start a development server
5 * - Open a browser tab at http://localhost:8787/ to see your worker in action
6 * - Run `npm run deploy` to publish your worker
7 *
8 * Learn more at https://developers.cloudflare.com/workers/
9 */
10
11export interface Env {
12 // Example binding to KV. Learn more at https://developers.cloudflare.com/workers/runtime-apis/kv/
13 // MY_KV_NAMESPACE: KVNamespace;
14 //
15 // Example binding to Durable Object. Learn more at https://developers.cloudflare.com/workers/runtime-apis/durable-objects/
16 // MY_DURABLE_OBJECT: DurableObjectNamespace;
17 //
18 // Example binding to R2. Learn more at https://developers.cloudflare.com/workers/runtime-apis/r2/
19 // MY_BUCKET: R2Bucket;
20 //
21 // Example binding to a Service. Learn more at https://developers.cloudflare.com/workers/runtime-apis/service-bindings/
22 // MY_SERVICE: Fetcher;
23 //
24 // Example binding to a Queue. Learn more at https://developers.cloudflare.com/queues/javascript-apis/
25 // MY_QUEUE: Queue;
26}
27
28export default {
29 async fetch(request: Request, env: Env, ctx: ExecutionContext): Promise<Response> {
30 return new Response('Hello World!');
31 },
32};