Files
tajniak81andClaude Opus 5 215c027ada Panel: give the API Server a name, and a tab to set it in
The Web App can be pointed at more than one DriverVault, but a server it
adds is only ever identified by the URL that was typed into the connect
dialog. Nothing on the other end says what it is called, so the switcher
has no name to show that the operator did not invent locally.

So the server now carries one. SERVER_NAME joins the config, defaulting to
"DriverVault API Server" so /api/health always has something a client can
display rather than an empty string every caller has to special-case.

GET/PUT /api/admin/server-config follow the pb-config and webapp-config
shape exactly: superadmin only, applied at runtime and then persisted to
.env, with the same "applied but could not be saved" warning when the write
fails. There is no /test sibling, because a name is a label and not an
address - there is nothing to probe. The length cap counts runes rather
than bytes, so a 64-character Polish or Danish name is not cut off at the
halfway mark.

/api/health reports it, unauthenticated, which is the point of the whole
change: a client adding this server by URL can label it from the probe it
already makes, instead of needing a second and authenticated call before it
can draw the entry.

In the panel it is a new API Server tab, first in the superadmin group
since it is this server itself, ahead of the PocketBase and Web App tabs
that describe what it talks to. Strings in all three languages, and the
route table in the README and the API reference tab both grow the two new
endpoints.

Known gap, deliberately not closed here: the compose files do not pass
SERVER_NAME, so under Docker a rename from the panel writes the container's
.env and no volume keeps it - it reverts to the default the next time the
container is recreated. Wiring it as ${SERVER_NAME:-} would make the host
.env authoritative, at the cost of the other trap the previous commit
documented, where the environment silently overrides the panel on every
restart. That is a call about the deployment, not about this endpoint.

Verified by new tests over the handler: the rename applies at runtime,
lands in .env, reaches /api/health, is rejected without touching .env when
blank or over-long, and accepts a name of exactly the limit in multi-byte
runes. go build, go vet and go test ./... pass. Drove the built panel in a
browser against a stub backend - the tab renders, loads the current name,
saves, and reads correctly in Polish - and ran the rebuilt api-server.exe
and webapp.exe end to end, confirming the embedded bundle really contains
the new tab and that SERVER_NAME reaches /api/health through both the
server itself and the Web App's proxy.

Not verified: no Docker build, so the images still serve the old panel
until they are rebuilt and pushed.

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
2026-08-21 19:59:00 +02:00

57 lines
2.7 KiB
Bash

# API Server configuration
# Copy to .env and adjust. The server also reads plain environment variables.
# Never commit the real .env file.
# Address the API Server listens on. A bare port (8080) is accepted too.
API_ADDR=:8080
# PocketBase base URL (no trailing slash). The API Server is the only thing that
# talks to PocketBase; it proxies /api/auth/* to this address, which is never
# exposed to clients. Editable at runtime from the panel (PocketBase section),
# which writes the change back into this file.
POCKETBASE_URL=http://10.2.1.10:8027
# PocketBase superuser service account. Every privileged flow runs through it:
# user/organization management and all car-domain database access. Leave unset
# and the server still starts — a superadmin can log in to the panel and
# configure it there; management endpoints return 503 until then.
POCKETBASE_ADMIN_EMAIL=
POCKETBASE_ADMIN_PASSWORD=
# This server's display name, reported by GET /api/health so a client pointed at
# several DriverVaults can tell them apart (the Web App's server switcher labels
# an added server with it). Editable at runtime from the panel (API Server
# section), which writes the change back into this file. Max 64 characters;
# unset falls back to "DriverVault API Server".
SERVER_NAME=
# CORS allowed origins for browser clients (comma separated, or * for any).
# Native mobile apps are not subject to CORS. Editable at runtime from the panel
# (Web App section), which writes the change back into this file.
CORS_ALLOW_ORIGINS=http://localhost:8090
# Web App address, probed by GET /api/status and shown on the panel. Editable at
# runtime from the panel (Web App section).
WEBAPP_URL=http://localhost:8090
# PocketBase auth collection holding app users (default: users).
AUTH_USERS_COLLECTION=users
# --- EV charging control (Anker Solix, OCPP) ---------------------------------
# Only relevant when a charger is set to own/proxy control mode. The charger
# dials in to /ocpp/{serial} on this server, authenticating with OCPP Basic auth
# (serial + per-charger control token). A plaintext ws:// would carry that token
# in the clear, so connections that did not arrive over TLS are rejected —
# disable only for local dev on a trusted network.
OCPP_REQUIRE_TLS=true
# The canonical ws(s):// base an operator points the charger at. Set this when
# the server sits behind a reverse proxy, where deriving the URL from request
# headers is unreliable. Empty = derive it.
OCPP_PUBLIC_URL=
# --- Legacy names -----------------------------------------------------------
# PB_URL, PB_ADMIN_EMAIL, PB_ADMIN_PASSWORD, PORT and CORS_ORIGINS are still
# honoured for older deployments; the POCKETBASE_*/API_ADDR names above win when
# both are set. AUTH_SECRET is gone — the server no longer mints its own JWTs.