inspect

Functionin security@fastly/js-compute 4.0.0since 3.38.0View source
inspect(request: Request, config: InspectConfig): InspectResponse

Inspect a request using the Fastly Next-Gen WAF.

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

Parameters

request: Request

The request to inspect.

config: InspectConfig

Configuration for the inspection.

Returns

Throws

  • {TypeError} If request is not a Request instance.
  • {TypeError} If overrideClientIp is not a valid IPv4 or IPv6 address.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/// <reference types="@fastly/js-compute" />
import { inspect } from "fastly:security";
async function app(event) {
const res = inspect(event.request, {
corp: "my-corp",
workspace: "my-workspace"
});
switch (res.verdict) {
case "allow":
return await fetch(event.request);
case "block":
return new Response("Request Blocked", { status: 400 });
case "unauthorized":
return new Response("Unauthorized", { status: 401 });
default:
return new Response("Unexpected verdict", { status: 500 });
}
}
addEventListener("fetch", (event) => event.respondWith(app(event)));