From 657adcc8a63d27df869f393abb0acfa1ee3feaf5 Mon Sep 17 00:00:00 2001 From: Willie Date: Wed, 18 Mar 2026 15:36:45 +0800 Subject: [PATCH] test+docs: add base path integration tests and reverse proxy guide - Integration tests: --base-path missing value, -b short flag, env var - Docs: --base-path flag in table, Nginx/Caddy examples, env var usage Ref: #85 --- tests/integration/ui_test.go | 30 ++++++++++++++++++++++ website/docs/reference/commands/ui.md | 37 +++++++++++++++++++++++++++ 2 files changed, 67 insertions(+) diff --git a/tests/integration/ui_test.go b/tests/integration/ui_test.go index ec141640b..d84c939df 100644 --- a/tests/integration/ui_test.go +++ b/tests/integration/ui_test.go @@ -59,3 +59,33 @@ func TestUI_ClearCache(t *testing.T) { t.Error("expected UI cache directory to be removed after --clear-cache") } } + +func TestUI_BasePathFlag_MissingValue(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + result := sb.RunCLI("ui", "--base-path") + result.AssertFailure(t) + result.AssertAnyOutputContains(t, "--base-path requires a value") +} + +func TestUI_BasePathShortFlag_MissingValue(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + result := sb.RunCLI("ui", "-b") + result.AssertFailure(t) + result.AssertAnyOutputContains(t, "--base-path requires a value") +} + +func TestUI_BasePathEnvVar(t *testing.T) { + sb := testutil.NewSandbox(t) + defer sb.Cleanup() + + // With env var but no config — should fail on missing config, not on unknown flag + sb.SetEnv("SKILLSHARE_UI_BASE_PATH", "/myapp") + result := sb.RunCLI("ui", "--no-open") + result.AssertFailure(t) + result.AssertAnyOutputContains(t, "run 'skillshare init' first") + result.AssertOutputNotContains(t, "unknown flag") +} diff --git a/website/docs/reference/commands/ui.md b/website/docs/reference/commands/ui.md index 6f5459663..9f115e596 100644 --- a/website/docs/reference/commands/ui.md +++ b/website/docs/reference/commands/ui.md @@ -27,6 +27,7 @@ Opens `http://127.0.0.1:19420` in your default browser. | `-g`, `--global` | | Run in global mode (uses `~/.config/skillshare/`) | | `--port ` | `19420` | HTTP server port | | `--host ` | `127.0.0.1` | Bind address (use `0.0.0.0` for Docker) | +| `-b`, `--base-path ` | | Sub-path for reverse proxy (e.g., `/skillshare`) | | `--no-open` | `false` | Don't open browser automatically | | `--clear-cache` | | Clear downloaded UI cache and exit | @@ -134,6 +135,42 @@ The web dashboard exposes a REST API at `/api/`. All endpoints return JSON. | PUT | `/api/skillignore` | Update `.skillignore` content | | GET | `/api/doctor` | Run all health checks (JSON) | +## Reverse Proxy + +Use `--base-path` to serve the dashboard under a sub-path behind a reverse proxy: + +```bash +skillshare ui --base-path /skillshare --host 0.0.0.0 --no-open +``` + +Or via environment variable: + +```bash +SKILLSHARE_UI_BASE_PATH=/skillshare skillshare ui --host 0.0.0.0 --no-open +``` + +### Nginx + +```nginx +location /skillshare/ { + proxy_pass http://127.0.0.1:19420; + proxy_set_header Host $host; + proxy_set_header X-Real-IP $remote_addr; +} +``` + +### Caddy + +``` +handle_path /skillshare/* { + reverse_proxy 127.0.0.1:19420 +} +``` + +:::tip +Without `--base-path`, the dashboard behaves identically to before — no configuration needed for direct access on `localhost:19420`. +::: + ## Docker Usage To use the web UI inside Docker (requires network access for first-time UI download):