Runlight.Routes (runlight v0.1.0)

Copy Markdown View Source

The dashboard, its JSON API, the tracker's script and endpoint, short links' API, OAuth, and the MCP server, under one base path (the SDK's routes.ts). Every answer is the SDK's byte for byte.

Make them with Runlight.routes/2 and answer a request with handle/2; Runlight.Plug does both for a Phoenix router or a Plug.Router.

Options, the SDK's in snake case:

  • :base_path - where the routes are mounted, default "/runlight".
  • :token - required to read stats, sent as Authorization: Bearer <token>, or once as ?token=<token>, which moves it into a cookie. Left out (or nil), it is RUNLIGHT_TOKEN. false leaves the routes open, for routes behind the app's own authentication. Without a token the dashboard runs open only in development, and answers 503 elsewhere.
  • :authorize - your own check instead of a token, a function of the request answering true, "member", "read", or false.
  • :accounts - true for sign-in accounts, with people and roles.
  • :cron_secret - also taken as a bearer on /api/check; default CRON_SECRET.
  • :observe_key - lets CMS plugins report AI agent fetches; default RUNLIGHT_OBSERVE_KEY.
  • :origin - the address people open the app at, such as "https://example.com".
  • :sign_in, :sign_out, :geo_credit, :own_hosts - as the SDK's.

Summary

Functions

An error the dashboard can show in its own language: code names it and params fill its placeholders, while error stays the English message.

Whether the app runs in development: NODE_ENV or RUNLIGHT_ENV is "development", or Mix runs in :dev.

A domain name, such as go.example.com.

Answers one request: a %Runlight.Http.Request{} whose URL is absolute, under the base path. Anything outside it answers a JSON 404.

A Host or X-Forwarded-Host value as a bare name: lowercase, with no port, no final dot, and no www.

What a manage token, held by a Runlight hub, may read and change: one site's goals, funnels, short links, link domains, email reports, and share links, along with its name, timezone, and retention, and tickets for the element picker.

Types

t()

@type t() :: %Runlight.Routes{
  account_of: term(),
  authorize: term(),
  base: term(),
  cron_secret: term(),
  geo_credit: term(),
  id: term(),
  observe_key: term(),
  origin: term(),
  own_hosts: term(),
  rl: term(),
  sign_in: term(),
  sign_out: term(),
  token: term(),
  token_made: term(),
  web: term()
}

Functions

coded(error, code, status, params \\ nil, headers \\ [])

An error the dashboard can show in its own language: code names it and params fill its placeholders, while error stays the English message.

development?()

@spec development?() :: boolean()

Whether the app runs in development: NODE_ENV or RUNLIGHT_ENV is "development", or Mix runs in :dev.

domain_name?(value)

A domain name, such as go.example.com.

handle(routes, request)

Answers one request: a %Runlight.Http.Request{} whose URL is absolute, under the base path. Anything outside it answers a JSON 404.

host_name(value)

A Host or X-Forwarded-Host value as a bare name: lowercase, with no port, no final dot, and no www.

manage_path?(method, path)

What a manage token, held by a Runlight hub, may read and change: one site's goals, funnels, short links, link domains, email reports, and share links, along with its name, timezone, and retention, and tickets for the element picker.