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. -
onBotSegmentAvailable. If your property has been configured to use Bot Manager Premier, this event happens afteronClientRequestand before checking if a response is available in cache.
You also need to create a manifest file called bundle.json that includes meta information as described in the table below.
| Setting name | Type | Description | Required |
|---|---|---|---|
edgeworker-version | String | Unique identifier for the EdgeWorkers version. | ✓ |
bundle-version | Integer | Bundle format version. | ✗ |
api-version | String | Version of JavaScript API when the EdgeWorkers code was created. | ✗ |
misc | Object | Information you can include in the manifest to identify the EdgeWorkers function. | ✗ |
description | String | Phrase describing the EdgeWorkers script function. | ✗ |
{
"edgeworker-version":"4.22.3",
"bundle-version":1,
"api-version":"0.3",
"description":"Language Redirect",
"misc":{
"author":"jsmith",
"git-commit":"4ce52c8ff4fdd1771e5347297ea5691b55c4f6ed",
"updated":"2027-09-23"
}
}You can also add support for subWorkers, Flexible composition, the True-Client-IP request header and set the JavaScript logging level in the bundle.json file.
| Object | Setting name | Type | Description |
|---|---|---|---|
config | client-ip-header | Boolean | When set to true, it enables the True-Client-IP request header. By default, this configuration setting is set to false. |
config.subrequest | invoke-for-edgeworker-clients | Boolean | When set to true, it enables support for subWorkers. By default, this configuration setting is set to false. |
config.logging | Supports thelevel, schema, and ds2id config settings. | Object | Set the JavaScript logging in the code bundle and deliver these logs using a DataStream 2 stream. By default, JavaScript logs are set to ERROR. |
level | Trace, Debug, Info, Warn, or Error | The default JavaScript logging level applied to the EdgeWorkers code bundle. You can use this parameter to override the default log level, ERROR. | |
ds2id | Integer | The Data Stream 2 stream id to associate with the JavaScript logging data. The stream needs to be active before you include it in the EdgeWorkers code bundle. When you add the logging config setting to the bundle.json file, the ds2id is required. | |
schema | String | Not currently in use. Use v1 as a placeholder. | |
dependencies.child | Supports the edgeWorkerId and version settings. | Object | Add information about Flexible composition |
edgeWorkerId | String | Unique identifier for the child EdgeWorkers version. | |
version | Integer | Version number of the child EdgeWorker version. |
Here's an example that includes all the supported settings in the bundle.json file.
{
"edgeworker-version":"4.22.3",
"bundle-version":1,
"api-version":"0.3",
"description":"Language Redirect",
"misc":{
"author":"jsmith",
"git-commit":"4ce52c8ff4fdd1771e5347297ea5691b55c4f6ed",
"updated":"2027-09-23"
},
"config": {
"logging": {
"level": "warn",
"ds2id": 123234,
"schema":"v1"
},
"subrequest": {
"invoke-for-edgeworker-clients": false
},
"client-ip-header": false
},
"dependencies":{
"child": {
"edgeWorkerId":12345,
"version": "active"
}
}
}Updated 5 days ago
