Handle slash-suffixed web root
All checks were successful
release / create-release (push) Successful in 9s
release / build-and-upload (pia-qbt-autoport-linux-amd64, amd64, linux, pia-qbt-autoport-linux-amd64) (push) Successful in 1m25s
release / build-and-upload (pia-qbt-autoport-macos-amd64, amd64, darwin, pia-qbt-autoport-macos-amd64) (push) Successful in 1m21s
release / build-and-upload (pia-qbt-autoport-macos-arm64, arm64, darwin, pia-qbt-autoport-macos-arm64) (push) Successful in 1m13s
release / build-and-upload (pia-qbt-autoport-windows-amd64.exe, amd64, windows, pia-qbt-autoport-windows-amd64.exe) (push) Successful in 1m14s

This commit is contained in:
2026-04-21 20:09:44 -05:00
parent 528cda0884
commit 4c0e87d326
2 changed files with 17 additions and 0 deletions

View File

@@ -57,6 +57,7 @@ func (a *App) Router() http.Handler {
mux.HandleFunc("/status", a.handleStatus)
mux.HandleFunc("/pia", a.handlePIA)
mux.HandleFunc("/_", a.handleWebRoot)
mux.HandleFunc("/_/", a.handleWebRoot)
mux.HandleFunc("/_/login", a.handleWebLogin)
mux.HandleFunc("/_/chart.js", a.handleWebChartJS)
mux.HandleFunc("/_/app.js", a.handleWebAppJS)

View File

@@ -64,6 +64,22 @@ func TestWebLoginPageSetsNoStoreHeaders(t *testing.T) {
}
}
func TestWebRootSlashRedirects(t *testing.T) {
app := NewApp(Config{APIKey: "super-secret"}, BuildInfo{}, "")
req := httptest.NewRequest(http.MethodGet, "/_/", nil)
rr := httptest.NewRecorder()
app.Router().ServeHTTP(rr, req)
res := rr.Result()
if res.StatusCode != http.StatusSeeOther {
t.Fatalf("status = %d, want %d", res.StatusCode, http.StatusSeeOther)
}
if got := res.Header.Get("Location"); got != "/_/login" {
t.Fatalf("Location = %q, want /_/login", got)
}
}
func TestWebConfigTogglePersistsToFile(t *testing.T) {
dir := t.TempDir()
configPath := filepath.Join(dir, "config.json")