Code bundle format
To create the EdgeWorkers bundle, you need a JavaScript source file called main.js that contains event handler definitions for when to execute the code:
-
onClientRequest. This event happens for every request as the request is received, before checking if a response is available in cache. -
onOriginRequest. This event happens just before sending the request to the origin. -
onOriginResponse. This event happens as the origin response is created. -
onClientResponse. This event happens for every request just before the client response is sent. -
responseProvider. This event happens if the response is not already found in cache. You can useresponseProviderto generate dynamic responses from various content and API sources.
You also need to create a manifest file called bundle.json that includes meta information as described in the table below.
📘 Limit
edgeworker-versioncharacters to alphanumeric, underscore, dash, dot, and tilde. The maximum length of theedgeworker-versionis 32 characters. You can’t use a single period (.) as the version.