Backend

Classin backend@fastly/js-compute 4.0.0View source

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.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
In 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

new Backend(configuration: BackendConfiguration)

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:
```js
const myBackend = new Backend({ name: 'fastly', target: 'www.fastly.com'});
```

Properties

name

stringread-onlysince 3.24.0View source

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"

isDynamic

booleanread-onlysince 3.24.0 View source

Whether this backend was dynamically created by the running service.

target

stringread-onlysince 3.24.0View source

The host target for the backend

hostOverride

stringread-onlysince 3.24.0View source

The host header override defined for the backend.

See https://docs.fastly.com/en/guides/specifying-an-override-host for more information.

port

numberread-onlysince 3.24.0View source

The backend port

connectTimeout

number | nullread-onlysince 3.24.0View source

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.

firstByteTimeout

number | nullread-onlysince 3.24.0View source

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.

betweenBytesTimeout

number | nullread-onlysince 3.24.0View source

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.

httpKeepaliveTime

numberread-onlysince 3.24.0View source

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 source

The TCP keepalive configuration, if TCP keepalive is enabled.

isSSL

booleanread-onlysince 3.24.0View source

Whether the backend is configured to use SSL.

tlsMinVersion

1 | 1.1 | 1.2 | 1.3 | nullread-onlysince 3.24.0View source

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.

tlsMaxversion

1 | 1.1 | 1.2 | 1.3 | nullread-onlysince 3.24.0View source

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

exists

staticView source
static exists(name: string): boolean

Returns a boolean indicating if a Backend with the given name exists or not.

Parameters

name: string

Returns

boolean

fromName

staticView source
static fromName(name: string): Backend

Returns the Backend instance with the given name, if one exists. If one does not exist, an error is thrown.

Parameters

name: string

Returns

health

Overload 1 of 2

health(): 'healthy' | 'unhealthy' | 'unknown'
View source

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

'healthy' | 'unhealthy' | 'unknown'

Overload 2 of 2

static health(backend: Backend): 'healthy' | 'unhealthy' | 'unknown'
View source
Deprecated: Use 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

'healthy' | 'unhealthy' | 'unknown'

toName

deprecatedView source
Deprecated: Use backend.name instead.
toName(): string

Returns the name associated with the Backend instance.

Returns

string

toString

deprecatedView source
Deprecated: Use backend.name instead.
toString(): string

Returns 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

string
import { Backend } from "fastly:backend";
const backend = new Backend({
name: "my-backend",
target: "my-site.com",
});
console.log(backend.toString()); // "my-backend"