2.5 KiB
2.5 KiB
@blade-and-brawn/api
ElysiaJS backend for Blade & Brawn: the level calculator endpoint, Printful/Webflow
commerce sync, and the admin API used by apps/portal.
Stack
- ElysiaJS on Bun, run in
node:clusterworker processes (seesrc/index.ts; worker count ismin(CPU cores, MAX_WORKER_COUNT)) - PostgreSQL via Kysely
- JWT cookie auth (
@elysia/jwt)
Environment variables
All required unless noted. See src/util.ts for the source of truth.
| Variable | Purpose |
|---|---|
PRINTFUL_AUTH |
Printful API token |
PRINTFUL_STORE_ID |
Printful store ID |
PRINTFUL_WEBHOOK_SECRET |
Shared secret appended to the Printful webhook URL |
WEBFLOW_SITE_ID |
Webflow site ID |
WEBFLOW_COLLECTION_PRODUCTS_ID |
Webflow CMS collection ID for products |
WEBFLOW_COLLECTION_SKUS_ID |
Webflow CMS collection ID for SKUs |
WEBFLOW_AUTH |
Webflow API token |
WEBFLOW_WEBHOOK_SECRET |
Webflow webhook signing secret |
AUTH_SECRET |
JWT signing secret (must match AUTH_SECRET in apps/portal) |
ADMIN_PASSWORD |
sha256 hex digest checked against on /auth/login |
DATABASE_URL |
Postgres connection string |
DATABASE_POOL_MAX |
Postgres pool size |
MAX_WORKER_COUNT |
Upper bound on cluster worker processes |
NODE_ENV |
optional, defaults to development |
LOG_LEVEL |
optional, defaults to info |
Scripts
Run from the repo root as bun run dev:api / bun run build:api, or from
this directory:
dev— run with hot reloadstart— run without hot reloadbuild— compile to a standalone binary atdist/serverdb:migrate:latest/:rollback/:up/:down/:reset— Kysely migrations (src/database/migrations)db:types:gen— regeneratesrc/database/out/db.d.tsfrom the database schemadb:seed— runsrc/database/seed.ts(loadsseed-data/standards-config.json)
Structure
src/server.ts— Elysia app: routes, plugins, error handlingsrc/services/— calculator, standards, commerce, events, event queuesrc/database/— Kysely instance, migrations, seed datasrc/scripts/— one-off scripts (e.g.register-webhooks.tsto (re)register Printful/Webflow webhooks against this API's domain)
Deployment
Deployed to Fly.io (fly.toml). After a domain changes, re-run
src/scripts/register-webhooks.ts with production env vars to point Printful's
and Webflow's webhooks at the new domain — see issue #3 for the full checklist.