Skip to main content

Overview

A complete Node 22 API built with Hono. It creates one shipd client per process, waits for ready() before it listens, evaluates new-checkout and search-variant per request, and closes the client on shutdown.

What’s in it

  • shipd.config.ts defines two flags. shipd push syncs them and writes src/generated/flags.ts.
  • src/lib/shipd.ts creates a singleton client with a server SDK key (shipd_sdk_server_…).
  • A middleware builds the evaluation context from the x-user-id header or the userId query parameter.
  • SIGINT / SIGTERM stop the HTTP server, then call shipd.close().

Files

package.json
tsconfig.json
shipd.config.ts
.env.example
shipd push and shipd types gen write this file. Commit it and do not edit it by hand.
src/generated/flags.ts
src/lib/shipd.ts
src/server.ts

Run it

Pushed flags serve their default. To see {"checkout":"new"}, open new-checkout in the dashboard, add a rule or change Fallthrough to true, and click Save environment. The server picks up the new snapshot without a restart.

Adapt it

  • Add attributes to the evaluation context from your auth layer (plan, country, organizationId). The server SDK does not infer location.
  • Percentage rollouts need a userId. Requests without one fall through.
  • On Node 20, pass WebSocket from the ws package or omit stream. Polling still runs every 30 seconds.
  • Omit stream to poll only. Set refreshIntervalMs: 0 for one fetch per process, for example in short-lived jobs.

Next