# Azion `Config` module

import DocButton from '~/components/webkit/DocButton.vue';

The **Config** module provides comprehensive configuration and validation for the Azion Platform. It supports applications, workloads, connectors, functions, storage, firewall rules, WAF settings, network lists, custom pages, and purge operations.

<DocButton href="/en/documentation/products/azion-lib/overview/" label="Go to Azion Libraries Overview" kind="secondary" size="medium" />

---

## Usage

You can configure your Azion application in two ways:

**1. Using JSDoc for type information:**

```javascript
/** @type {import('azion').AzionConfig} */
const config = {...}

export default config;
```

**2. Using the `defineConfig` function:**

```javascript
import { defineConfig } from 'azion/config';

const config = defineConfig({
  build: {
    entry: './src/index.js',
    preset: 'javascript',
  },
  // ... other configurations
});

export default config;
```

---

## Functions

### `defineConfig`

Configures and validates the options for Azion Applications.

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `config` | `AzionConfig` | The configuration object for the Azion Application. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `AzionConfig` | The validated configuration object. |

**Example**:

```javascript
import { defineConfig } from 'azion/config';

const config = defineConfig({
  build: {
    entry: './src/index.js',
    preset: 'javascript',
    bundler: 'esbuild',
  },
  applications: [
    {
      name: 'my-app',
      active: true,
      cache: [
        {
          name: 'my-cache',
          browser: { maxAgeSeconds: 3600 },
          edge: { maxAgeSeconds: 7200 },
        },
      ],
    },
  ],
  storage: [
    {
      name: 'my-storage',
      workloadsAccess: 'read_write',
      dir: './storage',
      prefix: 'app-data',
    },
  ],
});

export default config;
```

### `processConfig`

Processes the configuration object and returns a manifest.

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `config` | `AzionConfig` | The configuration object. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `object` | The processed manifest. |

**Example**:

```typescript
import { AzionConfig, processConfig } from 'azion';

const config: AzionConfig = {...};

const manifest = processConfig(config);
console.log(manifest);
```

### `convertJsonConfigToObject`

Converts a JSON configuration string to an `AzionConfig` object.

**Parameters**:

| Parameter | Type | Description |
|-----------|------|-------------|
| `config` | `string` | The JSON configuration string. |

**Returns**:

| Return Type | Description |
|-------------|-------------|
| `AzionConfig` | The configuration object. |

**Example**:

```javascript
import { convertJsonConfigToObject } from 'azion';

const manifestJson = {
  workloads: [
    {
      name: 'my-workload',
      active: true,
      domains: ['example.com'],
    },
  ],
};

const config = convertJsonConfigToObject(JSON.stringify(manifestJson));
console.log(config);
```

---

## Configuration sections

The `AzionConfig` object supports the following sections:

| Section | Description |
|---------|-------------|
| `build` | Build configuration (entry, preset, bundler). |
| `applications` | List of applications with cache, rules, and function instances. |
| `workloads` | Workload configurations for domain management. |
| `connectors` | HTTP, storage, or live ingest connectors. |
| `functions` | Functions configurations. |
| `storage` | Storage bucket configurations. |
| `firewall` | Firewall rules and configurations. |
| `waf` | Web Application Firewall settings. |
| `networkList` | Network lists (IP, ASN, countries). |
| `customPages` | Custom error page configurations. |
| `purge` | URLs or cache keys to purge. |
| `kv` | Key-Value storage configurations. |

---

## Types

### `AzionConfig`

The main configuration object.

| Property | Type | Description |
|----------|------|-------------|
| `build` | `AzionBuild` (optional) | Build configuration. |
| `applications` | `AzionApplication[]` (optional) | List of applications. |
| `workloads` | `AzionWorkload[]` (optional) | List of workloads. |
| `connectors` | `AzionConnector[]` (optional) | List of connectors. |
| `functions` | `AzionFunction[]` (optional) | List of functions. |
| `storage` | `AzionStorage[]` (optional) | List of storage configurations. |
| `firewall` | `AzionFirewall[]` (optional) | List of firewall configurations. |
| `waf` | `AzionWaf[]` (optional) | List of WAF configurations. |
| `networkList` | `AzionNetworkList[]` (optional) | List of network lists. |
| `customPages` | `AzionCustomPages[]` (optional) | List of custom pages. |
| `purge` | `AzionPurge[]` (optional) | List of purge operations. |
| `kv` | `AzionKV[]` (optional) | List of KV configurations. |

### `AzionBuild`

Build configuration options.

| Property | Type | Description |
|----------|------|-------------|
| `entry` | `string \| string[] \| Record<string, string>` (optional) | Entry file(s). |
| `preset` | `string \| AzionBuildPreset` (optional) | Build preset. |
| `bundler` | `'esbuild' \| 'webpack'` (optional) | Bundler to use. Default: `'esbuild'`. |
| `polyfills` | `boolean` (optional) | Include polyfills. |
| `extend` | `(context: T) => T` (optional) | Extend bundler configuration. |
| `memoryFS` | `object` (optional) | In-memory file system configuration. |

### `AzionApplication`

Application configuration.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | Application name (1-250 characters). |
| `active` | `boolean` (optional) | Whether active. Default: `true`. |
| `debug` | `boolean` (optional) | Enable debug mode. Default: `false`. |
| `edgeCacheEnabled` | `boolean` (optional) | Enable edge cache. Default: `true`. |
| `functionsEnabled` | `boolean` (optional) | Enable functions. Default: `false`. |
| `applicationAcceleratorEnabled` | `boolean` (optional) | Enable accelerator. Default: `false`. |
| `imageProcessorEnabled` | `boolean` (optional) | Enable image processor. Default: `false`. |
| `cache` | `AzionCache[]` (optional) | Cache configurations. |
| `rules` | `AzionRules` (optional) | Request/response rules. |
| `functionsInstances` | `FunctionInstance[]` (optional) | Function instances. |

### `AzionWorkload`

Workload configuration for domain management.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | Workload name (1-100 characters). |
| `active` | `boolean` (optional) | Whether active. Default: `true`. |
| `infrastructure` | `1 \| 2` (optional) | Infrastructure type. |
| `domains` | `string[]` | List of domains. |
| `workloadDomainAllowAccess` | `boolean` (optional) | Allow domain access. Default: `true`. |
| `tls` | `TLSConfig` (optional) | TLS configuration. |
| `protocols` | `ProtocolConfig` (optional) | Protocol configuration. |
| `mtls` | `MTLSConfig` (optional) | Mutual TLS configuration. |
| `deployments` | `Deployment[]` | List of deployments. |

### `AzionConnector`

Connector configuration.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | Connector name (1-255 characters). |
| `active` | `boolean` (optional) | Whether active. Default: `true`. |
| `type` | `'http' \| 'storage' \| 'live_ingest'` | Connector type. |
| `attributes` | `ConnectorAttributes` | Connector-specific attributes. |

### `AzionFunction`

Function configuration.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | Function name (1-250 characters). |
| `path` | `string` | Path to function file. |
| `runtime` | `'azion_js'` (optional) | Runtime. Default: `'azion_js'`. |
| `defaultArgs` | `object` (optional) | Default arguments. |
| `executionEnvironment` | `'application' \| 'firewall'` (optional) | Execution environment. |
| `active` | `boolean` (optional) | Whether active. Default: `true`. |
| `bindings` | `FunctionBindings` (optional) | Function bindings. |

### `AzionStorage`

Storage configuration.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | Storage name (6-63 characters). |
| `dir` | `string` | Local directory path. |
| `workloadsAccess` | `'read_only' \| 'read_write' \| 'restricted'` (optional) | Access permissions. |
| `prefix` | `string` | Storage prefix. |

### `AzionCache`

Cache configuration.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | Cache name (1-250 characters). |
| `stale` | `boolean` (optional) | Allow stale content. |
| `queryStringSort` | `boolean` (optional) | Sort query string parameters. |
| `methods` | `{ post?: boolean; options?: boolean }` (optional) | HTTP methods to cache. |
| `browser` | `{ maxAgeSeconds: number \| string }` (optional) | Browser cache settings. |
| `edge` | `{ maxAgeSeconds: number \| string }` (optional) | Edge cache settings. |
| `cacheByCookie` | `object` (optional) | Cache by cookie settings. |
| `cacheByQueryString` | `object` (optional) | Cache by query string settings. |
| `tieredCache` | `object` (optional) | Tiered cache settings. |

### `AzionFirewall`

Firewall configuration.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | Firewall name. |
| `active` | `boolean` (optional) | Whether active. |
| `functions` | `boolean` (optional) | Enable functions. |
| `networkProtection` | `boolean` (optional) | Enable network protection. |
| `waf` | `boolean` (optional) | Enable WAF. |
| `rules` | `AzionFirewallRule[]` (optional) | Firewall rules. |

### `AzionWaf`

WAF configuration.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | WAF name (1-250 characters). |
| `productVersion` | `string` (optional) | Product version. Default: `'1.0'`. |
| `engineSettings` | `WafEngineSettings` | WAF engine configuration. |

### `AzionNetworkList`

Network list configuration.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | Network list name (1-250 characters). |
| `type` | `'ip_cidr' \| 'asn' \| 'countries'` | List type. |
| `items` | `string[]` | List items (1-20000). |
| `active` | `boolean` (optional) | Whether active. Default: `true`. |

### `AzionPurge`

Purge configuration.

| Property | Type | Description |
|----------|------|-------------|
| `type` | `'url' \| 'cachekey' \| 'wildcard'` | Purge type. |
| `items` | `string[]` | URLs or patterns to purge. |
| `layer` | `'cache' \| 'tiered_cache'` (optional) | Cache layer. |

### `AzionKV`

KV storage configuration.

| Property | Type | Description |
|----------|------|-------------|
| `name` | `string` | KV storage name (1-255 characters). |