---
title: Shield
summary: Represents a Fastly shield location, used to route requests through a designated shield POP.
url: https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/shielding/class.Shield/
---

**Kind:** Class  
**Module:** [shielding](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/shielding/)  
**Package:** @fastly/js-compute 4.0.1  
**Since:** 3.37.0  
**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/shielding.d.ts#L42

Represents a [Fastly shield](https://www.fastly.com/documentation/guides/concepts/shielding/#shield-locations)
location, used to route requests through a designated shield POP.

**Note**: Can only be used when processing requests, not during build-time initialization.

```js
/// <reference types="@fastly/js-compute" />

import { Shield } from "fastly:shielding";

async function app(event) {
    const shield = new Shield('wsi-australia-au');
    // If running on the shield POP, fetch from the origin directly
    if (shield.runningOn()) {
        return await fetch('https://my-site.com/anything', { backend: 'my-backend' });
    }
    // Otherwise, route the request through the shield using an encrypted connection
    return await fetch(event.request, { backend: shield.encryptedBackend() });
}

addEventListener("fetch", (event) => event.respondWith(app(event)))
```

## Constructor

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/shielding.d.ts#L53

```javascript
new Shield(name: string)
```

Load information about the given shield.

Shield names are shield codes as listed in the
[shield locations](https://www.fastly.com/documentation/guides/concepts/shielding/#shield-locations)
documentation (e.g. `"pdx-or-us"` for Portland, OR, USA or `"paris-fr"` for Paris, France).

**Parameters**

- `name`: `string` — The shield code identifying the shield POP

**Throws**

- Throws an `Error` if no shield exists with the provided name

## Methods

### encryptedBackend

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/shielding.d.ts#L81

```javascript
encryptedBackend(configuration?: ShieldBackendConfiguration): Backend
```

Return a [Backend](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/backend/class.Backend/) representing an encrypted
connection to this shield POP. This is almost always the backend you want to use.

**Parameters**

- `configuration`: `ShieldBackendConfiguration` (optional) — Optional backend configuration

**Returns**

`Backend`

### runningOn

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/shielding.d.ts#L62

```javascript
runningOn(): boolean
```

Returns whether the code is currently running on (or effectively on) the given shield POP.

This may also return `true` when Fastly is routing traffic from the target shield POP to the
current POP for load balancing or performance reasons, since the result would be approximately
identical to running on the target shield itself.

**Returns**

`boolean`

### unencryptedBackend

**Source:** https://github.com/fastly/js-compute-runtime/blob/70cf30af4e657879b2d1e7eafab880e39e3a3f7d/types/shielding.d.ts#L71

```javascript
unencryptedBackend(configuration?: ShieldBackendConfiguration): Backend
```

Return a [Backend](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/backend/class.Backend/) representing an unencrypted
connection to this shield POP. Prefer [encryptedBackend](https://www.fastly.com/documentation/reference/compute/sdks/javascript/js-compute/shielding/class.Shield/#method-encryptedBackend) unless the data is already
encrypted, as data sent over this backend travels unencrypted over the open internet.

**Parameters**

- `configuration`: `ShieldBackendConfiguration` (optional) — Optional backend configuration

**Returns**

`Backend`
