Dashboard API

The dashboard exposes a REST API under /api. Its single source of truth is API-CONTRACT.md in the easy-devops repository — this page explains how to talk to it, and does not repeat the endpoint list.

The contract lives with the code

Every endpoint, request shape, response shape, auth rule and Socket.io event is documented in API-CONTRACT.md. That file is enforced by e2e/run.mjs, which compares the routes registered in src/dashboard/routes/ against it, so it cannot drift from the code. Read it there; this page only covers the transport rules you have to satisfy before any endpoint will answer.

Transport rules

Three checks run on every /api request, before authentication, in both auth modes. They are implemented in src/dashboard/lib/localRequest.js.

CheckRuleFailure
HostThe port must match the dashboard's. A direct request must use localhost, 127.0.0.1 or [::1]. A trusted local HTTPS proxy may supply the public host through exactly one X-Forwarded-Host header.403
OriginWhen present, a direct request must use the direct HTTP protocol, matching port and a loopback hostname. A trusted local HTTPS proxy request must use HTTPS and the effective forwarded host and port.403
X-EZ-Request: 1Required on every POST, PUT, PATCH, DELETE, and on the Socket.io handshake. Not required on a plain GET, but sending it everywhere is harmless and keeps one client path.403

A 403 from these checks is deliberately not a 401: logging in cannot fix "this request may not be made from where it came from". The body carries { error, reason, detail }.

Authentication and the session cookie

dashboardAuth is either password (the default) or none. In password mode, every endpoint except the auth router needs a logged-in session; without one it answers 401 { "error": "Unauthorized" }. Log in once with POST /api/login and reuse the cookie it sets — its name is connect.sid and it is HttpOnly, so a script has to keep it in a cookie jar rather than read it.

  • There is no default password. First-run setup requires a one-time code printed in the server's terminal or service log, or the choice of no-password mode when the dashboard listens on loopback only.
  • In none mode no session is required for a direct loopback request with no forwarding headers. Requests through a local HTTPS proxy or tunnel require a session.
  • The transport checks above are never relaxed in none mode. They are the only defence left.
  • Failed logins are rate limited per IP: 10 attempts per 15 minutes, answered with 429 and a Retry-After header.

A working curl walkthrough

Two requests are enough to show the whole pattern: log in, storing the cookie in a jar, then send a state-changing request with that jar and the X-EZ-Request: 1 header.

1 — log in and keep the cookie
curl -sS -c cookies.txt \
  -H "Content-Type: application/json" \
  -H "X-EZ-Request: 1" \
  -d '{"password":"your-dashboard-password"}' \
  http://127.0.0.1:6443/api/login

# {"ok":true}
# cookies.txt now holds the session (connect.sid)
2 — reuse the cookie for a change
curl -sS -b cookies.txt \
  -H "Content-Type: application/json" \
  -H "X-EZ-Request: 1" \
  -d '{
    "name": "example.com",
    "port": 3000,
    "backendHost": "127.0.0.1",
    "upstreamType": "http",
    "ssl": { "enabled": false },
    "performance": { "gzip": true },
    "security": { "rateLimit": false }
  }' \
  http://127.0.0.1:6443/api/domains
Read-only requests work the same way
curl -sS -b cookies.txt \
  -H "X-EZ-Request: 1" \
  http://127.0.0.1:6443/api/ssl

If you get a 403

Check the reason in the body. missing_request_header means X-EZ-Request: 1 is absent; host_not_local means the Host header is not a loopback name while the dashboard is bound to loopback. Calling 127.0.0.1 rather than a hostname avoids the second one. A 401 means the cookie is missing or expired — log in again.