Overview
A complete Node 22 API built with Hono. It creates one shipd client per process, waits forready() before it listens, evaluates new-checkout and search-variant per request, and closes the client on shutdown.
What’s in it
shipd.config.tsdefines two flags.shipd pushsyncs them and writessrc/generated/flags.ts.src/lib/shipd.tscreates a singleton client with a server SDK key (shipd_sdk_server_…).- A middleware builds the evaluation context from the
x-user-idheader or theuserIdquery parameter. SIGINT/SIGTERMstop the HTTP server, then callshipd.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
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
WebSocketfrom thewspackage or omitstream. Polling still runs every 30 seconds. - Omit
streamto poll only. SetrefreshIntervalMs: 0for one fetch per process, for example in short-lived jobs.