Config
Azion Lib functions of the @aziontech/config package that type an azion.config.js configuration, turn it into a manifest, and read a manifest back.
The @aziontech/config package is the Azion Lib library for the project configuration that the Azion CLI reads from azion.config.js. Its functions type a configuration object, turn it into a manifest, and turn a manifest back into a configuration object. The functions are synchronous, take no token, and run in Node.js.
For every key and property of the configuration object, with its type, refer to Configuration reference.
Install the package:
The samples on this page are ES modules that run in Node.js, and the TypeScript samples import types with import type. Each sample logs part of its result, and the output under it shows what the sample prints.
defineConfig
Returns the configuration object you pass, unchanged and typed as AzionConfig. defineConfig does not check the values: a configuration with an invalid value, such as an application with name: '', passes through without an error. To find where the Azion CLI checks the values, refer to defineConfig on the azion.config.js page.
| Parameter | Type | Required | Description |
|---|---|---|---|
config | AzionConfig | Yes | The configuration object. |
Returns the same config object.
This sample declares a JavaScript build:
Output:
This sample declares a build, an application with a cache setting, and an Object Storage bucket filled from a local folder:
Output:
A JavaScript file can also declare the type with a JSDoc annotation instead of calling defineConfig:
Output:
processConfig
Turns a configuration object into a manifest, an object whose keys use snake_case names. In a cache setting, for example, browser.maxAgeSeconds becomes browser_cache.max_age, and edge.maxAgeSeconds becomes modules.cache.max_age.
| Parameter | Type | Required | Description |
|---|---|---|---|
inputConfig | AzionConfig | Yes | The configuration object to turn into a manifest. |
Returns the manifest, typed any. The manifest holds 13 top-level keys, including the ones the configuration leaves out: build, purge, network_list, waf, storage, firewall, functions, applications, connectors, workloads, workload_deployments, custom_pages, and kv.
The manifest also carries settings that the configuration does not declare. In the sample below, the application declares a cache setting and no applicationAcceleratorEnabled, and the manifest sets application_accelerator.enabled to true.
This sample turns a configuration with one application into a manifest, then prints the manifest keys and the application:
Output:
convertJsonConfigToObject
Turns a manifest, passed as a JSON string, into a configuration object with camelCase keys. The function checks the manifest first, and it throws when the manifest lacks any of build, applications, workloads, and workload_deployments.
| Parameter | Type | Required | Description |
|---|---|---|---|
config | string | Yes | The manifest as a JSON string. |
Returns an AzionConfig object. A manifest that fails the check throws an Error; the message is in Errors.
This sample reads the manifest that azion build writes to .edge/manifest.json in the project folder, and prints the keys and the workloads of the configuration:
Output:
The output keeps the placeholders that the manifest holds, such as $WORKLOAD_NAME and $APPLICATION_NAME.
This sample passes a manifest that holds only workloads, and prints the message of the error the function throws:
Output:
Errors
convertJsonConfigToObject throws an Error when the manifest fails its check. The message numbers each problem and gives its text after Message:.
| Message | Cause | What to do |
|---|---|---|
The 'build', 'applications', 'workloads', and 'workload_deployments' fields are required in the manifest. | The JSON string lacks at least one of the four keys. | Pass a complete manifest, such as the .edge/manifest.json file that azion build writes. |
defineConfig throws no error for an invalid value, because it does not check values.
Types
The package exports AzionConfig and the type of each of its keys, such as AzionBuild, AzionApplication, and AzionWorkload. Import them with import type.
AzionConfig
The configuration object that every function on this page takes or returns. Every key is optional. Each type links to its properties on the azion.config.js page.
| Property | Type | Required | Description |
|---|---|---|---|
build | AzionBuild | No | How the project is built. |
applications | AzionApplication[] | No | The applications, with their cache settings, rules, and function instances. |
functions | AzionFunction[] | No | The functions. |
connectors | AzionConnector[] | No | The connectors, of type http, storage, or live_ingest. |
storage | AzionBucket[] | No | The Object Storage buckets and the local folders whose files go into them. |
firewall | AzionFirewall[] | No | The firewalls, with their rules. |
networkList | AzionNetworkList[] | No | The network lists, of type ip_cidr, asn, or countries. |
purge | AzionPurge[] | No | The URLs, cache keys, or wildcards to purge. |
waf | AzionWaf[] | No | The Web Application Firewall (WAF) configurations. |
workloads | AzionWorkload[] | No | The workloads that serve the applications on domains. |
customPages | AzionCustomPage[] | No | The custom error pages. |
kv | AzionKV[] | No | The KV Store namespaces. |