The dashboard is a page that talks to the HTTP API with the run token. It has no server state and no login of its own: the page is static, and everything it shows comes from requests it sends with the token you enter.
Turning it on
Set SCWRAP_INSTANCE_DASHBOARD=on for the stage (Variables) and apply the Stack. The Stack then creates the dashboard Worker, scwrap-instance-<stage>-dashboard, with no route and no workers.dev URL, and binds it to the controller as DASHBOARD. The controller forwards /dashboard/* to it and answers /dashboard with a redirect to /dashboard/. off, or unset, removes the Worker and the binding, and /dashboard is then an other path again.
Connecting
Open https://<instance>/dashboard/. The connect screen asks for the instance URL, filled in when the page is served by an instance, and a run token. The dashboard checks both with GET /scrapers before it shows anything.
The URL is kept in the browser's local storage. The token is kept in session storage, so it stays in that tab and is gone when the tab closes; Disconnect forgets it at once. The token is sent only to the instance, as Authorization: Bearer. A named run token limited to some Scrapers sees only those, as it does in the API.
What it shows
| Page | Shows |
|---|---|
| Scrapers | Every Scraper the token may use, with its Release, when it was deployed and its latest Run. |
| A Scraper | Its Runs, newest first, and its Definition: the input and output fields and the errors a Run can fail with, from GET /scrapers/<id>. A form built from the input schema starts a Run, or the input can be edited as JSON. |
| A Run | The result record, the input, the failure when it failed, and the first 100 items as a table. It refreshes every 2 seconds while the Run is running. Download items saves all of them as NDJSON, and Run again opens the start form with the same input. |
Starting a Run sends POST /scrapers/<id>/run with an Idempotency-Key, so a double click starts one Run.
The page
The page is served with a content security policy that allows only its own script and style, no framing and no referrer, and with cache-control: no-cache, so a deploy shows at once. It loads nothing from other origins. Requests to the instance are the only ones it sends.
On another origin
The dashboard is the @scwrap/ui package in the Scwrap repository. Its route(prefix) is an effect/http route that serves the page under a prefix, so any Effect HTTP app can mount it; the dashboard Worker is that route alone:
import { HttpRouter } from "effect/http";
import { route } from "./route.js";
const { handler } = HttpRouter.toWebHandler(route("/dashboard"));A page served from another origin than the instance's needs that origin in SCWRAP_INSTANCE_BROWSER_ORIGINS (Browsers); without it the browser refuses the instance's answers and the connect screen says so.
Source
- route.ts:
route, the page and its headers - worker.ts: the dashboard Worker
- client/: the page, built with Effect UI
- instance-dashboard.ts: the Stack's dashboard Worker