Worker

Cloudflare Worker for AXIS: /api/run proxy, keys, scripts, usage, and Durable Object stream relay.

This page

Worker

Abstract

The AXIS Cloudflare® Worker (worker/) is the edge data plane for the PWA: JSON APIs, optional script library (D1), API keys (KV), usage meters, on-chain proxy, and a WebSocket session relay (Durable Objects). It is not a full Pine Script™ interpreter in production today.

Honest runtime fact: POST /api/run proxies to EXTERNAL_BACKEND (typically Flask) unless PYODIDE_IN_WORKER=enabled and the in-worker path succeeds. In-worker Pyodide is planned / feature-gated — see Runtime and worker/RUNTIME.md.

Security (2.0.1+): gated /api/run (auth when API_KEYS / REQUIRE_RUN_AUTH), rate limits + body caps, fail-closed Worker auth when D1 is bound without API_KEYS KV, product-scoped CORS (not open *.pages.dev), OAuth env client ids over body clientId. See Auth and CORS.

Operator path: AXIS CLIaxis setup · axis deploy worker · axis health.

Conceptual model

Diagram

Rendering…

Infrastructure names (frozen)

SurfaceValue
Wrangler Worker scriptworker-axis — canonical https://worker.axis.hoox.sh
Pages projectaxis — canonical https://axis.hoox.sh
npm packageaxis-worker
Health JSON serviceworker-axis
Product brandAXIS

Pages --project-name is axis; custom domain is axis.hoox.sh. Worker URL is https://worker.axis.hoox.sh.

Interface surface

PathMethodRole
/, /healthGETHealth + feature flags (scripts, d1, keys, onchain)
/api/runPOSTRun script (proxy / gated Pyodide)
/api/keysGET/POSTValidate / create keys (X-Admin-Token for create)
/api/usageGETUsage stub / KV-backed counters
/api/scriptsCRUDScript library (Bearer)
/api/onchain/…GETPublic on-chain proxy (DefiLlama + GeckoTerminal allowlist; see below)
/api/streamWSSession DO relay

On-chain proxy routes (worker/src/onchain.ts)

Allowlisted GET only (public, no API key). Other /api/onchain/* paths return 404.

Worker pathUpstreamCache TTL
/api/onchain/healthlocal (providers + cache size)
/api/onchain/llama/protocolshttps://api.llama.fi/protocols~10 min
/api/onchain/llama/protocol/:slughttps://api.llama.fi/protocol/:slug~2 min
/api/onchain/gecko/networks/:network/pools/:address/ohlcv/:timeframehttps://api.geckoterminal.com/api/v2/networks/.../ohlcv/...~60 s
/api/onchain/gecko/search/poolshttps://api.geckoterminal.com/api/v2/search/pools~120 s

Gecko validation: network ^[a-z0-9_]+$; address EVM 0x+40 hex or Solana-style base58 32–48; timeframe day | hour | minute.
OHLCV query pass-through: aggregate, limit, currency, before_timestamp. Search: query, network, page, include.

Responses may include X-Axis-Onchain-Cache: HIT|MISS. Product guide: On-Chain data.

Entry: worker/src/index.ts.

Local entrypoints

cd frontend/worker
npm install   # or bun install
npm run dev   # wrangler dev → http://127.0.0.1:8787

Makefile: make worker-dev, make worker-deploy.

Implementation status

FeatureStatus
/api/runEXTERNAL_BACKENDWorks today
Admin /api/keysWorks (KV or shape-check)
Usage KV increment on runWorks when USAGE bound
SessionDO + /api/streamImplemented; binding often commented until provisioned
/api/scripts + D1 schemaImplemented; memory fallback without D1
Pyodide scaffoldpyodide_runtime.ts + flag; wheel pipeline incomplete
Response cache for /api/runDeferred

Page map

PageTopic
Runtime/api/run, proxy, Pyodide plan
Durable ObjectsStream fan-out
Data planeScripts, D1, drafts
AuthBearer keys, admin token
Bindingswrangler.toml, vars, provision

See also