MonetizationOS Docs
Getting StartedProxy Quickstart

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.

View on GitHub

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 install in the project

Deploy to Fastly

1. Authenticate

Create a local Fastly profile with your API token:

npx fastly profile create

2. Deploy

pnpm run deploy

On the first run (when there is no service_id in fastly.toml), the CLI runs an interactive wizard that:

  1. Creates a new Fastly Compute service
  2. Prompts for two backend hostnames:
    • origin — your website's hostname (for example news.example.com)
    • monetization_apiapi.monetizationos.com
  3. Creates the config Config Store and prompts for each key (see the table below)
  4. Creates the secrets Secret Store and prompts for the secret key (base64-encoded)

Config Store (config) keys

VariableDescription
MONETIZATION_OS_SECRET_KEYYour MonetizationOS secret key. Get it from environment settings.
ORIGIN_URLThe base URL of your origin server.
SURFACE_SLUGThe MonetizationOS surface to evaluate for every HTML request.
AUTHENTICATED_USER_JWT_COOKIE_NAMECookie name containing the authenticated user's JWT.
ANONYMOUS_SESSION_COOKIE_NAMECookie name for anonymous session identifiers.
SURFACE_DECISIONS_IGNORE_PATHSComma-separated regex patterns for paths that should skip surface decisions (optional)

Secret Store (secrets) keys

KeyValue
MONETIZATION_OS_SECRET_KEYYour 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' | base64

The 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 deploy

Troubleshooting: 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_KEY

Local development

1. Install dependencies

pnpm install

2. 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 start

Serves at http://127.0.0.1:7676 after build.

4. Run tests

pnpm test           # watch mode
pnpm test --run     # run once

5. Type check

pnpm exec tsc --noEmit

6. Build

pnpm run build

Compiles TypeScript to bin/main.wasm.

7. Deploy

pnpm run deploy

For canonical setup details and updates, see the project README.

Next steps

On this page