frontend: deep-link via ?instance=; client/frontend default to :9090; Makefile help; v1.1.0

- cmd/frontend/web: honour ?instance=<hostname> query parameter on the
  initial scope hydration so /view/?instance=lb-ams opens the dashboard
  scoped to that maglevd. The cookie is updated on consumption; an
  unknown name still falls back to the first server via App.tsx.

- cmd/client, cmd/frontend: --server now accepts bare hostnames. A new
  internal/netutil.EnsurePort canonicalises addresses by appending
  :9090 when no port is given, with bracketing for bare IPv6 literals.
  Unit test covers the IPv4/IPv6/bracketed/already-ported permutations.

- Makefile: new self-documenting `help` target as the default rule;
  every user-facing target now carries a `## ` description that the
  awk-based help auto-extracts. fixstyle-web skips with a friendly
  message when prettier isn't installed instead of failing on npx.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
2026-05-01 10:27:16 +02:00
parent 9a3c5c5dc0
commit fb61e72e06
9 changed files with 142 additions and 29 deletions
+7 -1
View File
@@ -16,8 +16,14 @@ import (
"time"
buildinfo "git.ipng.ch/ipng/vpp-maglev/cmd"
"git.ipng.ch/ipng/vpp-maglev/internal/netutil"
)
// defaultGRPCPort is the maglevd gRPC port. Lets operators write
// "--server chbtl2" or MAGLEV_FRONTEND_SERVERS=chbtl2,chbtl3 without
// the redundant ":9090" suffix on every entry.
const defaultGRPCPort = "9090"
func main() {
if err := run(); err != nil {
slog.Error("startup-fatal", "err", err)
@@ -133,7 +139,7 @@ func parseServers(s string) []string {
var out []string
for _, part := range strings.Split(s, ",") {
if p := strings.TrimSpace(part); p != "" {
out = append(out, p)
out = append(out, netutil.EnsurePort(p, defaultGRPCPort))
}
}
return out
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
+1 -1
View File
@@ -5,7 +5,7 @@
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link rel="icon" type="image/x-icon" href="/view/favicon.ico" />
<title>maglev</title>
<script type="module" crossorigin src="/view/assets/index-3m4Pjc8_.js"></script>
<script type="module" crossorigin src="/view/assets/index-AJWk_JCf.js"></script>
<link rel="stylesheet" crossorigin href="/view/assets/index-3BvNJ7QB.css">
</head>
<body>
+21 -1
View File
@@ -37,7 +37,27 @@ function writeCookie(name: string | undefined) {
}
}
const [scope, setScopeRaw] = createSignal<string | undefined>(readCookie());
// readInitialScope honours a `?instance=<hostname>` deep-link query
// parameter ahead of the cookie, so a shared URL like /view/?instance=lb-ams
// opens the dashboard scoped to that maglevd. The named instance is also
// written back to the cookie so a subsequent reload without the param
// keeps the same selection. App.tsx still validates this against the
// fetched snapshot list, so a stale or unknown name falls back to the
// first server rather than leaving the SPA pinned to a ghost.
function readInitialScope(): string | undefined {
try {
const fromURL = new URLSearchParams(window.location.search).get("instance");
if (fromURL) {
writeCookie(fromURL);
return fromURL;
}
} catch {
// window.location is unavailable in non-browser contexts.
}
return readCookie();
}
const [scope, setScopeRaw] = createSignal<string | undefined>(readInitialScope());
// setScope wraps the raw signal setter so every selection change writes
// back to the cookie. Callers use this exactly like the old setScope —