Fastly Compute
Fastly Compute (JavaScript) still uses the fetch event listener model rather than the modules-style default export you see on Cloudflare Workers. The DaloyJS adapter wraps that registration so you only call one function.
- platformfetch eventaddEventListener('fetch', ...)
- adapterinstallFastlyListener(app)event.respondWith(app.fetch(...))
- coreapp.fetch(Request)routing · hooks · handler
- platformResponse
When to choose Fastly Compute
- You already use Fastly's edge network and want REST API logic on the same plane.
- You want WebAssembly-compiled JS (
js-compute-runtime) for tight cold starts. - You're comfortable without
node:*modules.
Install
Entrypoint
That helper is equivalent to:
Passing event.waitUntil keeps the instance alive until OTLP telemetry is exported after the response. installFastlyListener does that for you. Without it the flush still starts, but Fastly may stop the instance before it finishes.
fastly.toml
Fastly Compute requires manifest_version = 3. The [scripts] build command has to bundle TypeScript to a single JS file first, then run js-compute-runtime against that bundle, the runtime only accepts JavaScript input.
Declared backends, KV stores, config stores, and secrets live under the same [local_server.*] /[setup.*] tables, see the fastly.toml reference for the full schema.
Deploy
Client IP
installFastlyListener(app) passes Fastly's event.client.address to the App as the trusted peer address, so IP-keyed guards (rateLimit(), autoBan(), ipRestriction()) identify the real client. Declare that nothing sits in front of Compute:
Do not use behindProxy: { hops: 1 } here: Compute hands your code the client's own X-Forwarded-For, so that header is client-controlled. If you call toFastlyHandler(app) yourself, pass the address as the third argument:
A value that is not an IP address is ignored.
Gotchas
- No
node:*modules. Avoid the Node session store, the Redis rate-limit store, and multipart helpers that depend onnode:stream: use the fetch-based alternatives. - Every outbound HTTP call your REST API makes (to a database API, auth service, or third-party endpoint) must be declared as a backend in
fastly.toml. Arbitraryfetch("https://...")calls fail at runtime without one. - KV stores, config stores, and secrets are also declared in
fastly.tomlunder[setup].
See also
- Adapters overview
- Cloudflare Workers, similar constraints, modules format.