|
| 1 | +--- |
| 2 | +hide_title: false |
| 3 | +hide_table_of_contents: false |
| 4 | +pagination_next: null |
| 5 | +pagination_prev: null |
| 6 | +--- |
| 7 | + |
| 8 | +# setDefaultDynamicBackendConfig() |
| 9 | + |
| 10 | +The **`setDefaultDynamicBackendConfig()`** allows setting backend configuration defaults that should apply to any newly created dynamic backends via the `new Backend()` constructor. |
| 11 | + |
| 12 | +### Parameters |
| 13 | + |
| 14 | +- `defaultDynamicBackendConfig` |
| 15 | + |
| 16 | + - : An Object which contains the generic configuration options to apply to newly created Backends. |
| 17 | + - `connectTimeout` _: number_ _**optional**_ |
| 18 | + - Maximum duration in milliseconds to wait for a connection to this backend to be established. |
| 19 | + - If exceeded, the connection is aborted and a 503 response will be presented instead. |
| 20 | + - Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is negative or greater than or equal to 2^32 |
| 21 | + - `firstByteTimeout` _: number_ _**optional**_ |
| 22 | + - Maximum duration in milliseconds to wait for the server response to begin after a TCP connection is established and the request has been sent. |
| 23 | + - If exceeded, the connection is aborted and a 503 response will be presented instead. |
| 24 | + - Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is negative or greater than or equal to 2^32 |
| 25 | + - `betweenBytesTimeout` _: number_ _**optional**_ |
| 26 | + - Maximum duration in milliseconds that Fastly will wait while receiving no data on a download from a backend. |
| 27 | + - If exceeded, the response received so far will be considered complete and the fetch will end. |
| 28 | + - Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is negative or greater than or equal to 2^32 |
| 29 | + - `useSSL` _: boolean_ _**optional**_ |
| 30 | + - Whether or not to require TLS for connections to this backend. |
| 31 | + - `dontPool` _: boolean_ _**optional**_ |
| 32 | + - Determine whether or not connections to the same backend should be pooled across different sessions. |
| 33 | + - Fastly considers two backends “the same” if they're registered with the same name and the exact same settings. |
| 34 | + - In those cases, when pooling is enabled, if Session 1 opens a connection to this backend it will be left open, and can be re-used by Session 2. |
| 35 | + - This can help improve backend latency, by removing the need for the initial network / TLS handshake(s). |
| 36 | + - By default, pooling is enabled for dynamic backends. |
| 37 | + - `tlsMinVersion` _: 1 | 1.1 | 1.2 | 1.3_ _**optional**_ |
| 38 | + - Minimum allowed TLS version on SSL connections to this backend. |
| 39 | + - If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead. |
| 40 | + - Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is not 1, 1.1, 1.2, or 1.3 |
| 41 | + - `tlsMaxVersion` _: 1 | 1.1 | 1.2 | 1.3_ _**optional**_ |
| 42 | + - Maximum allowed TLS version on SSL connections to this backend. |
| 43 | + - If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead. |
| 44 | + - Throws a [`RangeError`](../../globals/RangeError/RangeError.mdx) if the value is not 1, 1.1, 1.2, or 1.3 |
| 45 | + - `certificateHostname` _: string_ _**optional**_ |
| 46 | + - Define the hostname that the server certificate should declare. |
| 47 | + - Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is an empty string. |
| 48 | + - `caCertificate` _: string_ _**optional**_ |
| 49 | + - The CA certificate to use when checking the validity of the backend. |
| 50 | + - Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is an empty string. |
| 51 | + - `ciphers` _: string_ _**optional**_ |
| 52 | + - List of OpenSSL ciphers to support for connections to this origin. |
| 53 | + - If the backend server is not able to negotiate a connection meeting this constraint, a 503 response will be presented instead. |
| 54 | + - [List of ciphers supported by Fastly](https://developer.fastly.com/learning/concepts/routing-traffic-to-fastly/#use-a-tls-configuration). |
| 55 | + - Throws a [`TypeError`](../../globals/TypeError/TypeError.mdx) if the value is an empty string. |
| 56 | + - `clientCertificate` _: object_ _**optional**_ |
| 57 | + - The client certificate to provide for the TLS handshake |
| 58 | + - `certificate` _: string_ |
| 59 | + - The PEM certificate string. |
| 60 | + - `key` _: SecretStoreEntry_ |
| 61 | + - The `SecretStoreEntry` to use for the key, created via [`SecretStore.prototype.get`](../../fastly:secret-store/SecretStore/prototype/get.mdx) or alteratively via [`SecretStore.fromBytes`](../../fastly:secret-store/SecretStore/fromBytes.mdx). |
| 62 | + - `httpKeepalive` _: number_ _**optional**_ |
| 63 | + - Enable HTTP keepalive, setting the timout in milliseconds. |
| 64 | + - `tcpKeepalive` _: boolean | object_ _**optional**_ |
| 65 | + - Enable TCP keepalive. When an object, optionally setting the keepalive configuration options. |
| 66 | + - `timeSecs` _: number_ _**optional**_ |
| 67 | + - Configure how long to wait after the last sent data over the TCP connection before starting to send TCP keepalive probes. |
| 68 | + - `intervalSecs` _: number_ _**optional**_ |
| 69 | + - Configure how long to wait between each TCP keepalive probe sent to the backend to determine if it is still active. |
| 70 | + - `probes` _: number_ _**optional**_ |
| 71 | + - Number of probes to send to the backend before it is considered dead. |
| 72 | + |
| 73 | +## Syntax |
| 74 | + |
| 75 | +```js |
| 76 | +setDefaultDynamicBackendConfig(defaultConfig) |
| 77 | +``` |
| 78 | + |
| 79 | +### Return value |
| 80 | + |
| 81 | +None. |
| 82 | + |
| 83 | +## Examples |
| 84 | + |
| 85 | +In this example an explicit Dynamic Backend is created and supplied to the fetch request, with timeouts and TLS options provided from the default backend configuration options. |
| 86 | + |
| 87 | + |
| 88 | +<Fiddle config={{ |
| 89 | + "type": "javascript", |
| 90 | + "title": "Explicit Dynamic Backend Example", |
| 91 | + "origins": [ |
| 92 | + "https://http-me.glitch.me" |
| 93 | + ], |
| 94 | + "src": { |
| 95 | + "deps": "{\n \"@fastly/js-compute\": \"^1.0.1\"\n}", |
| 96 | + "main": ` |
| 97 | +/// <reference types="@fastly/js-compute" /> |
| 98 | +import { allowDynamicBackends } from "fastly:experimental"; |
| 99 | +import { Backend, setDefaultDynamicBackendConfig } from "fastly:backend"; |
| 100 | +allowDynamicBackends(true); |
| 101 | +setDefaultDynamicBackendConfig({ |
| 102 | + connectTimeout: 1000, |
| 103 | + firstByteTimeout: 15_000, |
| 104 | + betweenBytesTimeout: 10_000, |
| 105 | + useSSL: true, |
| 106 | + sslMinVersion: 1.3, |
| 107 | + sslMaxVersion: 1.3 |
| 108 | +}); |
| 109 | +async function app() { |
| 110 | + // For any request, return the fastly homepage -- without defining a backend! |
| 111 | + // Timeouts and TLS configuration still get set from the default backend configuration above. |
| 112 | + const backend = new Backend({ |
| 113 | + name: 'fastly', |
| 114 | + target: 'fastly.com', |
| 115 | + hostOverride: "www.fastly.com" |
| 116 | + }); |
| 117 | + return fetch('https://www.fastly.com/', { |
| 118 | + backend // Here we are configuring this request to use the backend from above. |
| 119 | + }); |
| 120 | +} |
| 121 | +addEventListener("fetch", event => event.respondWith(app(event))); |
| 122 | +` |
| 123 | + }, |
| 124 | + "requests": [ |
| 125 | + { |
| 126 | + "enableCluster": true, |
| 127 | + "enableShield": false, |
| 128 | + "enableWAF": false, |
| 129 | + "method": "GET", |
| 130 | + "path": "/status=200", |
| 131 | + "useFreshCache": false, |
| 132 | + "followRedirects": false, |
| 133 | + "tests": "", |
| 134 | + "delay": 0 |
| 135 | + } |
| 136 | + ], |
| 137 | + "srcVersion": 1 |
| 138 | +}}> |
| 139 | + |
| 140 | +```js |
| 141 | +/// <reference types="@fastly/js-compute" /> |
| 142 | +import { allowDynamicBackends } from "fastly:experimental"; |
| 143 | +import { Backend } from "fastly:backend"; |
| 144 | +allowDynamicBackends(true); |
| 145 | +setDefaultDynamicBackendConfig({ |
| 146 | + connectTimeout: 1000, |
| 147 | + firstByteTimeout: 15_000, |
| 148 | + betweenBytesTimeout: 10_000, |
| 149 | + useSSL: true, |
| 150 | + sslMinVersion: 1.3, |
| 151 | + sslMaxVersion: 1.3 |
| 152 | +}); |
| 153 | +async function app() { |
| 154 | + // For any request, return the fastly homepage -- without defining a backend! |
| 155 | + const backend = new Backend({ |
| 156 | + name: 'fastly', |
| 157 | + target: 'fastly.com', |
| 158 | + hostOverride: "www.fastly.com" |
| 159 | + }); |
| 160 | + return fetch('https://www.fastly.com/', { |
| 161 | + backend // Here we are configuring this request to use the backend from above. |
| 162 | + }); |
| 163 | +} |
| 164 | +addEventListener("fetch", event => event.respondWith(app(event))); |
| 165 | +``` |
| 166 | + |
| 167 | +</Fiddle> |
0 commit comments