Skip to content

Deploy

View as Markdown

This section is for whoever hosts the Towers API. If you only call it, you do not need it.

The API is a single Node.js service with a SQLite file beside it. It needs Node.js 24 or Docker, and very little else.

  1. Get the code onto the server and go to the backend folder.

  2. Start it

    Terminal window
    docker compose up -d --build

    The API listens on 127.0.0.1:7552, reachable only from the server itself. Its data lives in a Docker volume named towers-data, so it survives restarts and rebuilds.

  3. Put HTTPS in front of it

    Use a reverse proxy to add TLS and to publish only the keyed Engine endpoints /towers, /placements, /recoveries and /comparisons. With Caddy, which fetches certificates by itself. Replace towers-api.example.invalid with your API hostname in the examples below.

    Caddyfile
    towers-api.example.invalid {
    @engine path /api/v1/towers /api/v1/placements /api/v1/recoveries /api/v1/comparisons
    handle @engine {
    reverse_proxy 127.0.0.1:7552
    }
    handle {
    respond 404
    }
    }
  4. Issue a key and try it

    Terminal window
    docker compose exec api node dist/cli/keys create "Smoke test"
    Terminal window
    curl https://towers-api.example.invalid/api/v1/towers \
    -H "Authorization: Bearer twr_..." \
    -H "Content-Type: application/json" \
    -d '{"program":{"contracts":[{"contractRef":"C-1","currency":"USD","layers":[{"layerName":"First excess","layerType":"XOL","lowerLimit":100,"upperLimit":200,"isUnlimited":false,"order":100}]}],"risks":[{"riskId":"R-1","contractRefs":["C-1"]}]}}'

    A 200 with a risks array means it is working. Revoke the test key afterwards.

Terminal window
cd backend
npm ci
npm run build
SEED_DEMO=false node dist/main

Keep it running with your process manager of choice, such as systemd.

All are environment variables, and all are optional.

Variable Default
PORT 7552 The port to listen on.
DATABASE_PATH data/programs.db (/data/programs.db in Docker) The SQLite file holding API keys and stored programs.
SEED_DEMO on Set to false to disable demo seeding, including after legacy rows are cleared. The Docker setup does this.
FRONTEND_URL http://localhost:5173 The one browser origin allowed to call the API, for the bundled programs app.

Everything worth keeping is the one SQLite file: the fingerprints of the keys you have issued, and any stored programs. Copy it on a schedule. If it is lost, every client needs a new key.

Terminal window
git pull
docker compose up -d --build

API keys are preserved. Stored requests in the old format without program.contracts are cleared on startup; current-format imports are kept. Missing demos are re-seeded after a legacy clear unless SEED_DEMO=false.