Skip to main content

Fetch Handler

还没翻译译自英文(developers.cloudflare.com)本页 8 段都还没译

Background

Incoming HTTP requests to a Worker are passed to the fetch() handler as a Request object. To respond to the request with a response, return a Response object:

export default {
	async fetch(request, env, ctx) {
		return new Response('Hello World!');
	},
};

Note

The Workers runtime does not support XMLHttpRequest (XHR). Learn the difference between XMLHttpRequest and fetch() in the MDN documentation.

Parameters

  • request Request

    • The incoming HTTP request.
  • env object

  • ctx.waitUntil(promisePromise) : void

  • ctx.passThroughOnException() : void