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
This commit is contained in:
Willie
2026-03-18 22:35:02 +08:00
parent 214c8b993c
commit 657adcc8a6
2 changed files with 67 additions and 0 deletions
+30
View File
@@ -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")
}
+37
View File
@@ -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 <port>` | `19420` | HTTP server port |
| `--host <host>` | `127.0.0.1` | Bind address (use `0.0.0.0` for Docker) |
| `-b`, `--base-path <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):