Backend
Class for dynamically creating new Fastly Backends.
Note: Dynamic backends are by default disabled at the Fastly service level. Contact Fastly Support to request dynamic backends on Fastly Services.
To disable the usage of dynamic backends, see enforceExplicitBackends.
1234567891011121314151617181920212223In this example an explicit Dynamic Backend is created and supplied to the fetch request, the response is then returned to the client.```js/// <reference types="@fastly/js-compute" />import { Backend } from "fastly:backend";async function app() { // For any request, return the fastly homepage -- without defining a backend! const backend = new Backend({ name: 'fastly', target: 'fastly.com', hostOverride: "www.fastly.com", connectTimeout: 1000, firstByteTimeout: 15000, betweenBytesTimeout: 10000, useSSL: true, tlsMinVersion: 1.3, tlsMaxVersion: 1.3, }); return fetch('https://www.fastly.com/', { backend // Here we are configuring this request to use the backend from above. });}addEventListener("fetch", event => event.respondWith(app(event)));```Constructor
Creates a new Backend instance.
Note: Backend() can only be constructed with new. Attempting to call it
without new throws a TypeError.
All optional generic options can have their defaults set via
setDefaultDynamicBackendConfig. This includes all configuration
options except for name, target, hostOverride, sniHostname and grpc.
Parameters
- configuration: BackendConfiguration
Construct a new backend with all properties set to their default values:```jsconst myBackend = new Backend({ name: 'fastly', target: 'www.fastly.com'});```Properties
The name of the backend.
import { Backend } from "fastly:backend";const backend = new Backend({ name: "my-backend", target: "my-site.com",});console.log(backend.name); // "my-backend"Whether this backend was dynamically created by the running service.
The host target for the backend
The host header override defined for the backend.
See https://docs.fastly.com/en/guides/specifying-an-override-host for more information.
The backend port
The connect timeout for the backend in milliseconds, if available.
When not set or in environments that do not support this property (such as Viceroy), null may be returned.
The first byte timeout for the backend in milliseconds, if available.
When not set or in environments that do not support this property (such as Viceroy), null may be returned.
The between bytes timeout for the backend in milliseconds, if available.
When not set or in environments that do not support this property (such as Viceroy), null may be returned.
The HTTP keepalive time for the backend in milliseconds, or 0 if no keepalive is set.
tcpKeepalive
null | { timeSecs: number | null; intervalSecs: number | null; probes: number | null }read-onlysince 3.24.0View sourceThe TCP keepalive configuration, if TCP keepalive is enabled.
Whether the backend is configured to use SSL.
The minimum TLS version number this backend will use.
When not used, or for environments that do not support this feature (such as Viceroy), null may be returned.
The maximum TLS version number this backend will use.
When not used, or for environments that do not support this feature (such as Viceroy), null may be returned.
Methods
static exists(name: string): booleanReturns a boolean indicating if a Backend with the given name exists or not.
Parameters
- name: string
Returns
static fromName(name: string): BackendReturns the Backend instance with the given name, if one exists. If one does not exist, an error is thrown.
Parameters
- name: string
Returns
Overload 1 of 2
health(): 'healthy' | 'unhealthy' | 'unknown'Returns a string representing the health of this backend. Possible values are:
- "healthy" - The backend's health check has succeeded, indicating the backend is working as expected and should receive requests.
- "unhealthy" - The backend's health check has failed, indicating the backend is not working as expected and should not receive requests.
- "unknown" - The backend does not have a health check configured.
Returns
Overload 2 of 2
static health(backend: Backend): 'healthy' | 'unhealthy' | 'unknown'backend.health() (Backend.prototype.health) instead.Returns a string representing the health of the given Backend instance. Possible values are:
"healthy" - The backend's health check has succeeded, indicating the backend is working as expected and should receive requests. "unhealthy" - The backend's health check has failed, indicating the backend is not working as expected and should not receive requests. "unknown" - The backend does not have a health check configured.
Parameters
- backend: Backend
Returns
backend.name instead.toName(): stringReturns the name associated with the Backend instance.
Returns
backend.name instead.toString(): stringReturns the name associated with the Backend instance.
The Backend object overrides the toString() method of Object; it does not inherit
Object.prototype.toString(). For Backend values, the toString method returns the
name given to the Backend object during construction.
Returns
import { Backend } from "fastly:backend";const backend = new Backend({ name: "my-backend", target: "my-site.com",});console.log(backend.toString()); // "my-backend"