Fastly Edge Compute Proxy
The MonetizationOS Fastly Edge Compute Proxy is an open source integration that adds server-side monetization decisions to static or edge-served HTML.
What is Fastly Edge Compute?
Fastly Edge Compute runs serverless JavaScript or TypeScript on Fastly's global edge network, close to your users.
Why use the proxy worker?
The MonetizationOS proxy edge compute lets you evaluate and apply monetization behavior at the edge before HTML reaches the browser.
Installation and configuration
Prerequisites
- A Fastly account with an API token
- The Fastly CLI — installed as a dev dependency after you run
pnpm installin the project
Deploy to Fastly
1. Authenticate
Create a local Fastly profile with your API token:
npx fastly profile create2. Deploy
pnpm run deployOn the first run (when there is no service_id in fastly.toml), the CLI runs an interactive wizard that:
- Creates a new Fastly Compute service
- Prompts for two backend hostnames:
origin— your website's hostname (for examplenews.example.com)monetization_api—api.monetizationos.com
- Creates the
configConfig Store and prompts for each key (see the table below) - Creates the
secretsSecret Store and prompts for the secret key (base64-encoded)
Config Store (config) keys
| Variable | Description |
|---|---|
MONETIZATION_OS_SECRET_KEY | Your MonetizationOS secret key. Get it from environment settings. |
ORIGIN_URL | The base URL of your origin server. |
SURFACE_SLUG | The MonetizationOS surface to evaluate for every HTML request. |
AUTHENTICATED_USER_JWT_COOKIE_NAME | Cookie name containing the authenticated user's JWT. |
ANONYMOUS_SESSION_COOKIE_NAME | Cookie name for anonymous session identifiers. |
SURFACE_DECISIONS_IGNORE_PATHS | Comma-separated regex patterns for paths that should skip surface decisions (optional) |
Secret Store (secrets) keys
| Key | Value |
|---|---|
MONETIZATION_OS_SECRET_KEY | Your MonetizationOS secret key from environment settings. Store it base64-encoded in the Secret Store. |
To encode your secret key before entering it:
echo -n 'your_secret_key' | base64The store names config and secrets are hardcoded in src/env.ts (new ConfigStore('config') / new SecretStore('secrets')). If you use different names during setup, update the CONFIG_STORE_NAME and SECRET_STORE_NAME constants in src/env.ts to match.
When the wizard finishes, note the Service ID in the output and add it to fastly.toml:
service_id = "<YOUR_SERVICE_ID>"That prevents the wizard from running again on future deploys.
Subsequent deploys
pnpm run deployTroubleshooting: 400 Bad Request (duplicate: name) on secret store entry
If a deploy fails partway through, the CLI may clean up the service but leave Secret Store entries. The next deploy can fail with a duplicate name. Delete the orphaned entry, then deploy again:
npx fastly secret-store list
# Note the Store ID for 'secrets', then:
npx fastly secret-store-entry delete --store-id <SECRET_STORE_ID> --name MONETIZATION_OS_SECRET_KEYLocal development
1. Install dependencies
pnpm install2. Configure local values
All local config is defined in fastly.toml under [local_server.config_stores.config.contents]. Update those values to match your environment.
For the secret store, set the base64-encoded value under [[local_server.secret_stores.secrets]]:
[[local_server.secret_stores.secrets]]
key = "MONETIZATION_OS_SECRET_KEY"
data = "<base64-encoded secret key>"3. Run locally
pnpm startServes at http://127.0.0.1:7676 after build.
4. Run tests
pnpm test # watch mode
pnpm test --run # run once5. Type check
pnpm exec tsc --noEmit6. Build
pnpm run buildCompiles TypeScript to bin/main.wasm.
7. Deploy
pnpm run deployFor canonical setup details and updates, see the project README.
Next steps
- Learn the broader concept and architecture in Proxies
- Explore the request pipeline in the Proxy API reference