# Add e-signatures and clickwrap to a Fly.io app

> Add e-signatures and clickwrap to a Fly.io app: the esigncomply package in a Node.js image, the key in fly secrets, and Managed Postgres for the receipt.

Source: https://esigncomply.com/fly-io

Platform · Fly.io

To add e-signatures and clickwrap to a Fly.io app, run the `esigncomply` package in a Node.js image and store the secret key with `fly secrets set`. The app creates the session and confirms the record, and Managed Postgres keeps the pinned versions and the receipt for both Machines. Esign Comply seals each acceptance as an independent record.

Follow the quickstart and each signature is a valid electronic signature under the U.S. ESIGN Act, state UETA laws and New York's ESRA, and each clickwrap is built the way courts require: clear notice of the terms, an unmistakable act of assent, and a sealed record of both.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/fly-io)

`npm install esigncomply pg`

[Fly.io quickstart](https://esigncomply.com/docs/quickstart/fly-io)

Free plan: 10 live signatures a month and a full test mode. No card required.

Last updated November 26, 2026

Run locally for Fly.io before publishing

**Server**

server.js (excerpt)

```js
// Step 4: create the session with the secret key. The browser gets the client token only.
if (req.method === "POST" && url.pathname === "/api/ceremony") {
  const { data: session, error } = await esc.sessions.create(
    {
      profile: process.env.ESIGNCOMPLY_PROFILE_ID,
      signer,
      documents: [
        { document: DOCUMENTS.terms, version: "current" },
        { document: DOCUMENTS.privacy, version: "current" },
      ],
      // The page that runs the ceremony: the origin the browser reports, plus its path.
      context: { url: `${req.headers.origin ?? url.origin}/signup`, locale: "en-US", purpose: "account_signup" },
    },
    { idempotencyKey: `signup-${signer.external_id}-${randomUUID()}` },
  );
  if (error) return json(res, 502, { error: error.code });
  // In Postgres, not in memory: the confirmation can reach the other Machine.
  await savePinned(signer.external_id, session.documents.map((d) => d.version_id).sort());
  return json(res, 200, { clientToken: session.client_token, apiUrl: session.api_url, documents: session.documents });
```

**fly.toml**

`fly.toml`

```toml
# fly.toml
app = "esigncomply-quickstart"
primary_region = "iad"

[deploy]
  release_command = "node migrate.js"

[http_service]
  internal_port = 3000
  force_https = true
  auto_stop_machines = "stop"
  auto_start_machines = true
  min_machines_running = 0

  [[http_service.checks]]
    grace_period = "10s"
    interval = "30s"
    method = "GET"
    timeout = "5s"
    path = "/health"
```

**Confirm**

server.js (excerpt)

```js
// Step 6: confirm the record with the secret key before the account exists.
if (req.method === "POST" && url.pathname === "/api/signup/confirm") {
  const { recordId } = await body(req);
  const { data: record, error } = await esc.records.get(String(recordId));
  const expected = await getPinned(signer.external_id);
  const confirmed =
    !error &&
    SEALED.includes(record.status) &&
    record.livemode === LIVE &&
    record.signer.external_id === signer.external_id &&
    JSON.stringify(record.documents.map((d) => d.version_id).sort()) === JSON.stringify(expected);
  console.log(confirmed ? `confirmed ${record.id} (${record.status})` : "refused");
  if (!confirmed) return json(res, 409, { confirmed: false });
  // Only now create the account. The record ID and the receipt go in the same row.
  await saveReceipt(signer.external_id, record.id, record.receipt);
  return json(res, 200, { confirmed: true, recordId: record.id });
```

**Stop signal**

server.js (excerpt)

```js
// Fly.io stops a Machine with SIGINT unless fly.toml names another signal. Finish the open
// requests, close the pool, exit.
for (const signal of ["SIGINT", "SIGTERM"]) {
  process.on(signal, () => {
    server.close(() => close().finally(() => process.exit(0)));
    server.closeIdleConnections();
  });
}
```

Integrate with Fly.io

## How do you integrate Esign Comply with Fly.io?

On Fly.io the server half is one Node.js image, built from the Dockerfile that Fly.io's generator writes. `fly.toml` names the port, the health check and the release command that creates the table. An app with a service runs on two Machines, and Fly Proxy stops idle ones, so the pinned versions go to Managed Postgres.

Fly Machines are fast-launching VMs, the basic compute unit of the Fly.io platform.

Source: [Fly.io documentation, High availability: run multiple Machines](https://docs.fly.io/blueprints/resilient-apps-multiple-machines), read on November 25, 2026.

[Fly.io quickstart](https://esigncomply.com/docs/quickstart/fly-io) · [All platforms](https://esigncomply.com/platforms)

Where each part lives on Fly.io

- **Server** · `server.js`
- **fly.toml** · `fly.toml`
- **Confirm** · `server.js`
- **Stop signal** · `server.js`

Run on 2026-11-26 in the image built from the Dockerfile that Fly.io's generator wrote for this code (@flydotio/dockerfile 0.7.15 with its cmd option, Node.js 24.22.1, Docker 25.0.18 with the classic builder), on PostgreSQL 17, with esigncomply 1.0.4, pg 8.23.1, the browser SDK script build and the conformance check from esigncomply 1.0.4, against the API in test mode. The release command was run the way Fly.io runs it, in place of the image's command, and the same code was also started with Node.js 24.22.1 on the machine. fly.toml was written from Fly.io's configuration reference and was not validated, because fly config validate (flyctl 0.5.17) needs a login. The Fly.io settings are from Fly.io's documentation as of 2026-11-25. Nothing has been deployed to Fly.io yet.

Three steps

## How does Esign Comply fit with Fly.io?

Each step uses a feature Fly.io already has. The secret key stays on the server side of Fly.io in all three.

1. **An app secret holds the key**

   Set `ESIGNCOMPLY_API_KEY` with `fly secrets set`. Fly.io stores secrets in an encrypted vault and injects them into every Machine of the app as environment variables. The SDK reads the key from `process.env`, and neither `fly.toml` nor the image contains it. Source: [Fly.io documentation, Secrets and Fly Apps](https://docs.fly.io/apps/secrets), read on November 25, 2026.

2. **The app creates the session**

   `POST /api/ceremony` runs in your Node.js server on a Machine. It calls `esc.sessions.create` and returns the client token. The same server serves the signup page, and the browser SDK records the ceremony from the signer's device.

3. **Managed Postgres keeps the receipt**

   `fly mpg attach` sets `DATABASE_URL` as a secret of the app, with the connection string of the cluster. The session route stores the pinned versions in a table there. The confirm route reads the record with the secret key, compares it with the row, and writes the record ID and the receipt into it. Source: [Fly.io documentation, fly mpg attach](https://docs.fly.io/flyctl/cmd/fly_mpg_attach), read on November 25, 2026.

Fly.io setup

## Where do the key, the preview hosts and the webhook go on Fly.io?

Four settings carry an Esign Comply integration on Fly.io. What is said here about Fly.io was read from its own documentation, and the quickstart has each command.

### Secrets

`fly secrets set` updates each Machine of a deployed app, which restarts it. With `--stage`, the value waits for the next deploy. Set `ESIGNCOMPLY_LIVE=true` on the production app only, beside the live key: the server expects live records only there.

Source: [Fly.io documentation, Secrets and Fly Apps](https://docs.fly.io/apps/secrets), read on November 25, 2026.

### The app file and the release command

`internal_port` in `fly.toml` has to be the port the server listens on, on `0.0.0.0`. Fly Proxy sends requests only to Machines that pass the service check, which the quickstart points at `/health`. The release command runs `migrate.js` in a temporary Machine before the others are updated.

Source: [Fly.io documentation, App configuration (fly.toml)](https://docs.fly.io/reference/configuration), read on November 25, 2026.

### Review apps and test mode

A review app answers on `pr-<PR number>-<repository owner>-<repository name>.fly.dev` by default. A test key refuses a host it does not know: list the exact host under Domains in the Esign Comply dashboard as a test origin. Never list the shared suffix `fly.dev`.

Source: [Fly.io documentation, Git Branch Preview Environments](https://docs.fly.io/blueprints/review-apps-guide), read on November 25, 2026.

### The registered domain and the webhook

Register your custom domain and verify it with one DNS record. `fly certs add` attaches it to the app. A production app on its `fly.dev` host verifies with a file at `/.well-known/esigncomply.txt`. For the `record.completed` webhook, add a route to the server and register its production URL under Webhooks in the Esign Comply dashboard.

Source: [Fly.io documentation, Custom domains](https://docs.fly.io/networking/custom-domain), read on November 25, 2026.

Read on November 25, 2026: [Fly.io documentation, Create an app with Fly Launch](https://docs.fly.io/launch/create), [Fly.io documentation, App configuration (fly.toml)](https://docs.fly.io/reference/configuration), [Fly.io documentation, Secrets and Fly Apps](https://docs.fly.io/apps/secrets), [Fly.io documentation, App Availability and Resiliency](https://docs.fly.io/apps/app-availability), [Fly.io documentation, Autostop/autostart Machines](https://docs.fly.io/launch/autostop-autostart), [Fly.io documentation, Health Checks](https://docs.fly.io/reference/health-checks), [Fly.io documentation, The Machine Runtime Environment](https://docs.fly.io/machines/runtime-environment), [Fly.io documentation, fly mpg attach](https://docs.fly.io/flyctl/cmd/fly_mpg_attach), [Fly.io documentation, Git Branch Preview Environments](https://docs.fly.io/blueprints/review-apps-guide), [Fly.io documentation, Custom domains](https://docs.fly.io/networking/custom-domain).

Copy-paste prompt

## What prompt adds Esign Comply clickwrap to a Fly.io app?

Paste this into Cursor, Claude Code or the AI coding tool that is open on your project. It names the packages that exist, where the secret key goes on Fly.io, what to build and what never to do, and it ends with the rules block for your project.

The rules block lives at [/rules.md](https://esigncomply.com/rules.md). Added to your project's instruction file, it makes every later session build signing and acceptance flows the same way. The [prompt generator](https://esigncomply.com/product/prompt-generator) writes the long version, with your own document and profile IDs.

[Pages for each AI tool](https://esigncomply.com/build)

Prompt: Esign Comply clickwrap on Fly.io

```
Add Esign Comply clickwrap to my app on Fly.io: a signup form where the user accepts the Terms of Service and the Privacy Notice with a checkbox and a button.

Read these first and follow them exactly. If something conflicts with existing code, or you are unsure how to implement a step, stop and ask. Do not invent API methods, packages or legal wording.
- https://esigncomply.com/docs/quickstart/fly-io.md (the steps and the tested code for Fly.io)
- https://esigncomply.com/setup.md (the order of API calls)
- https://esigncomply.com/auth.md (how to handle the keys)

Fly.io facts
- Packages (the only ones that exist): esigncomply (server, Node.js 20.19 or later, an ES module) and @esigncomply/browser. Without a bundler, load the browser SDK from https://esigncomply.com/sdk/v1/esigncomply.js.
- The secret key is the app secret ESIGNCOMPLY_API_KEY, set with "fly secrets set". Never put it in fly.toml, in the Dockerfile or in the image. Never print it.
- Listen on 0.0.0.0 on the internal_port of fly.toml. PORT is not among the variables Fly.io sets in a Machine.
- The image's command is ["node", "server.js"], not npm, so the process receives the stop signal itself. That signal is SIGINT unless fly.toml sets kill_signal: handle SIGINT and SIGTERM.
- An app with a service runs on two Machines, and Fly Proxy stops idle ones. Keep the pinned version IDs in Postgres (DATABASE_URL, set by "fly mpg attach"), never in a variable of the process. Create the table in the release_command of fly.toml.
- Expect live records only where the app secret ESIGNCOMPLY_LIVE is "true". A review app is another app with secrets of its own: give it the test key.
- The page is on screen before the script has a session: render the checkbox disabled and enable it when observeAssent has resolved.

Build
1. Verify the key: GET /v1/usage with ESIGNCOMPLY_API_KEY. Stop if it fails.
2. Register the Terms of Service and the Privacy Notice as documents and publish one version of each from the documents in this project. If the project has none, register short sample documents and say so in your report. Never write or change the wording of the real documents. Create a profile: jurisdictions ["US-FED"], method "checkbox", assurance_level "L1".
3. Server: POST /api/ceremony creates the session with esc.sessions.create and an Idempotency-Key, saves the signer ID and the pinned version IDs in Postgres, and returns only clientToken, apiUrl and documents.
4. Server: GET /legal/terms and /legal/privacy render the registered version from esc.documents.versions.getContent inside <article data-esc-document>, unmodified.
5. Browser: EsignComply.attach({ clientToken, apiUrl }), presentDocument for each link, observeAssent({ region, checkbox, submit }), then complete() from the user's real click.
6. Server: POST /api/signup/confirm reads the record with esc.records.get and requires: status is "recorded", "timestamped" or "anchored"; livemode is as expected; the signer ID and version IDs equal the row in Postgres. Only then create the account, and store the record ID and the receipt in the same row.

Never
- Never pre-check the box, auto-submit, or call .click() on the user's behalf.
- Never use "By continuing" or "By clicking below" wording. The notice names the button by its label and each document by its registered name.
- Never put the secret key, or any call that uses it, in code that reaches the browser.
- Never show "signed" or "accepted" before the server has confirmed the record.
- Never fall back to an acceptance with no record when a session is refused.

Check before you report success
- Run: npx esigncomply check --url http://localhost:3000/signup --callback http://localhost:3000/api/signup/confirm
  Fix every finding marked "block". List every finding marked "warn".
- Report the files you created or changed, anything you did not implement and why, and the conformance summary.

Then add the rules block to this project's instruction file: https://esigncomply.com/rules.md
```

3 things to watch

## What goes wrong when you add e-signatures on Fly.io?

These are specific to Fly.io. Each one was seen while the quickstart's code was run, or is in Fly.io's own documentation.

- **The generated Dockerfile starts the app through npm**

  Fly.io's generator wrote `CMD [ "npm", "run", "start" ]` for the quickstart, and Fly.io stops a Machine by sending `SIGINT` to the main process. In the test, that image was still running 15 seconds after `SIGINT`. Regenerated with `--cmd '["node", "server.js"]'`, it closed the database pool and exited with code 0 in under a second.

  Source: [Fly.io documentation, App configuration (fly.toml)](https://docs.fly.io/reference/configuration), read on November 25, 2026.

- **Two Machines, and an idle one is stopped**

  Fly.io creates two Machines for an app with a service, and with `auto_stop_machines` Fly Proxy stops them when the app is idle. Memory is not shared between Machines. In the test, two Node.js processes with the pinned versions in a `Map` ended in `409`. With Postgres, a second container confirmed the record.

  Source: [Fly.io documentation, App Availability and Resiliency](https://docs.fly.io/apps/app-availability), read on November 25, 2026.

- **Fly.io does not hand the server a PORT**

  `PORT` is not among the variables Fly.io's documentation lists for a Machine. The quickstart's server falls back to `3000`, and `internal_port` in `fly.toml` has to be the same number. The server listens on `0.0.0.0`, which is where Fly Proxy reaches it.

  Source: [Fly.io documentation, The Machine Runtime Environment](https://docs.fly.io/machines/runtime-environment), read on November 25, 2026.

## Where are the Fly.io quickstart and the API reference?

Start with the quickstart: it carries every file this page excerpts, in the order you write them.

- Quickstart

  **[Fly.io quickstart](https://esigncomply.com/docs/quickstart/fly-io)**

  Step by step, from install to your first sealed test record, with every file and the output of each step.

- Reference

  **[API reference](https://esigncomply.com/docs/api)**

  Every endpoint, field and error code. Sessions, records and documents are the three this page uses.

- Guide

  **[Server confirmation](https://esigncomply.com/docs/guides/server-confirmation)**

  The one place access is granted: what to compare, and the webhook that backs the check up.

Verifiable

## What does Esign Comply record for a signature on Fly.io?

The same record on every stack and platform. Your Fly.io code creates the session and confirms the record, and the browser SDK reports what happened on the page. Esign Comply seals the result where your code cannot change it. The record itself is described on [Evidence and verification](https://esigncomply.com/product/evidence).

- **Observed and asserted fields**

  Every field is tagged. Observed is what the browser SDK and the API saw: the box unchecked at load, the tick from a trusted user event, the notice text, the terms version by hash, the server time. Asserted is what your app said, such as the user's email.

- **A signed receipt**

  `complete()` returns a receipt signed with ES256, using keys you do not hold. Your server stores it next to the user, and `GET /v1/records/{id}/receipt` returns it again.

- **An external timestamp**

  An outside authority timestamps the hash of every live record (RFC 3161), so the time on the record does not rest on your clock or on ours.

- **An offline verifier**

  Each record has an evidence report (PDF) and an evidence package (ZIP). Anyone you send the package to checks the acceptance with the open-source `esigncomply-verify`, without an account.

[How sealing and verification work](https://esigncomply.com/product/evidence) · [Observed and asserted, in the docs](https://esigncomply.com/docs/concepts/observed-and-asserted) · [The offline verifier](https://esigncomply.com/docs/sdk/verify)

Record

`rec_Z4m8`

simple · L1

Recorded

Written durably, receipt signed with ES256

Timestamped

External RFC 3161 token over the record hash

Anchored

Public anchor pending

Checkbox changed by a trusted user event · observed

Terms of Service, version dv_3kT9 · observed

Server time 2026-11-21T15:03:20.291Z · observed

Signer email dana@example.org · asserted

record_hash sha256:5be7… · example record

## Questions about e-signatures on Fly.io

### How does test mode work on Fly.io preview URLs?

A review app is a separate Fly.io app with a host of its own, by default `pr-<PR number>-<repository owner>-<repository name>.fly.dev`. A test key refuses that host until you list it under Domains as a test origin. On `localhost` a test key works with no setup.

### Where should the receipt be stored on Fly.io?

In Managed Postgres, beside the signer ID and the record ID. The confirm route writes both once the record is confirmed. `fly mpg attach` gives the app `DATABASE_URL`, and the quickstart uses one row for the pinned versions and the receipt.

### Why should Node.js be the main process of the Fly.io image?

Because Fly.io sends the stop signal to the main process of the image, `SIGINT` by default. In the test, the image that started the app through npm was still running 15 seconds after `SIGINT`, and after `SIGTERM` it exited with code 1. With `node server.js` as the command it exited with code 0 in under a second.

### Does a Fly.io review app inherit the production key?

No. Fly.io's review apps are separate apps, created by a GitHub Action for each pull request, and a new app has no secrets. The workflow passes them in from GitHub secrets: give it the test key and the test IDs, and leave `ESIGNCOMPLY_LIVE` out.

### Was fly.toml validated by Fly.io?

No. `fly config validate` needs a login, so the file was written from Fly.io's configuration reference as of November 25, 2026 and not validated. The code passed the conformance check in the image built from the Dockerfile Fly.io's generator wrote. Nothing has been deployed to Fly.io yet: `fly launch`, secrets, Managed Postgres and the `fly.dev` host are proven only by a deployment.

### Other platforms

- [Railway](https://esigncomply.com/railway)
- [Render](https://esigncomply.com/render)
- [Google Cloud Run](https://esigncomply.com/google-cloud-run)

### Stacks used with Fly.io

- [Node.js](https://esigncomply.com/nodejs)
- [Express](https://esigncomply.com/express)
- [Next.js](https://esigncomply.com/nextjs)

[All platforms](https://esigncomply.com/platforms) · [All stacks](https://esigncomply.com/stacks) · [Clickwrap API](https://esigncomply.com/clickwrap) · [E-signature API](https://esigncomply.com/sign)

## Run the signing flow on your Fly.io Machines. Leave the record to us.

[Get an API key](https://esigncomply.com/signup) · [Read the docs](https://esigncomply.com/docs/quickstart/fly-io)

Free plan: 10 live signatures a month and a full test mode. No card required.

Fly.io is a trademark of its owner. Esign Comply is not affiliated with it. What this page says about Fly.io is from Fly.io's documentation or from a test run, as marked, on November 25, 2026. `/fly-io.md` is this page as Markdown.

---

Every page on esigncomply.com has a Markdown version at the same URL plus `.md` (the home page is `https://esigncomply.com/index.md`). https://esigncomply.com/llms.txt lists them.

---

Esign Comply is the e-signature API and clickwrap API for developers who build their own signing flow in their own UI: it supplies the ceremony rules as a generated prompt for AI coding tools, records events in direct browser ceremonies, and seals independent, verifiable evidence.
