Create a code bundle
Refer to these guidelines to create an EdgeWorkers code bundle.
EdgeWorkers functions are defined in a file entitled main.js. You also need to create a manifest file called bundle.json. These are packaged together, along with any other dependencies as a compressed .tgz file.

For example, a package called mybundle.tgz includes two files:
-
main.js. The JavaScript source that contains event handler functions. -
bundle.json. The manifest file that includes necessary meta information.
📘 The EdgeWorkers code bundle cannot contain any executable files.
Any files with a
.\_<xx>notation inside the EdgeWorkers code bundle are ignored.
👍 You cannot re-use a version that you deleted from an EdgeWorker ID. You need to use a new unique version in the
bundle.jsonand re-package it and any other files with yourmain.jsfile. | Name | Type | Required | Description | | --- | --- | :---: | --- | |edgeworker-version| String | ✓ | Unique identifier for the version
If you delete a version from an EdgeWorker ID you cannot re-use it. Follow the steps below to create a new code bundle that you can use to create a version. | |bundle-version| Integer | ✗ | Bundle format version | |api-version| String | ✗ | Version of JavaScript API that the functions are coded against | |description| String | ✗ | Descriptive phrase for the code function | |misc| Object | ✗ | Miscellaneous data you can include in the manifest to identify the function |
Follow these steps to create the bundle.
👍 You can also use the code bundle editor to create an EdgeWorker version.
- Create the JavaScript source in a file called
main.js.
You can also enable subWorkers and change the default JavaScript logging level in the main.js file.
- Each time you create a new version of the code bundle you need to increment the
edgeworker-versionin thebundle.jsonfile.
- Compress the files into a code bundle.
Make sure that the code bundle doesn’t contain any executable files. If you include any executable files in the .tgz it will fail when you try to upload it.
Once you have created the code bundle, you can use the EdgeWorkers Management application to create an EdgeWorker version.
Code bundle configuration settings
These configuration settings let you enable or disable EdgeWorkers features from within the code bundle.
Enable subWorkers
To enable subWorkers you need to add the invoke-for-edgeworker-clients config setting to the bundle.json file and set it to true. For more information, go to Create a subWorker in this guide.
If the configuration setting is set to false or not included, the EdgeWorkers function will return an information status 22, SubworkerNotEnabled, if a sub-request is made to the EdgeWorkers URL. The sub-request will continue to process without invoking the EdgeWorker.
Change the default JavaScript logging level
You can 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.
👍 For more information about how to deliver the logs, go to the Use DataStream 2 to deliver JavaScript logs tutorial.
To change the default JavaScript log level you need to add the logging config setting to the bundle.json file.
You can change the ds2id using the EdgeWorkers CLI.
Enable True Client-IP
Pass the True-Client-IP request header forward in a sub-request. When enabled, the origin receives the IP address of the client.