Move web UI from /ui/ to /web/ path prefix

The web UI is now mounted at /web/ (previously /ui/) — cmd/server/main.go
wraps web.Server.Handler with http.StripPrefix("/web", ...), so
internal/web's own routes stay unprefixed (/, /login, /logout,
/shares/..., /static/...) and only the outer mux adds the prefix. All
templates, redirects, and cookie paths updated accordingly. The root '/'
route reverts to the original unauthenticated welcome page (linking to
/web/), and /cal/, /card/, /files/ are unaffected.

Also gitignore the bin/ build output directory.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
This commit is contained in:
2026-08-19 07:29:32 +02:00
co-authored by Copilot
parent ab3c7f44d5
commit 4dba55c807
15 changed files with 58 additions and 52 deletions
+11 -10
View File
@@ -29,19 +29,20 @@ func NewServer(cfg *config.Config, st *store.Store, dbase *db.DB, logger *slog.L
return &Server{cfg: cfg, store: st, dbase: dbase, logger: logger}
}
// Handler returns the http.Handler serving the web UI, mounted at "/ui/"
// Handler returns the http.Handler serving the web UI, mounted at "/web/"
// by the caller (cmd/server). staticFS serves the compiled Tailwind CSS
// and any other static assets.
// and any other static assets. Since it's mounted with a path prefix,
// the caller must wrap this handler in http.StripPrefix("/web", ...).
func (s *Server) Handler(staticFS http.FileSystem) http.Handler {
mux := http.NewServeMux()
mux.Handle("/ui/static/", http.StripPrefix("/ui/static/", http.FileServer(staticFS)))
mux.Handle("/static/", http.StripPrefix("/static/", http.FileServer(staticFS)))
mux.HandleFunc("/ui/login", s.handleLogin)
mux.HandleFunc("/ui/logout", s.handleLogout)
mux.HandleFunc("/ui/", s.requireLogin(s.handleDashboard))
mux.HandleFunc("/ui/shares/calendar", s.requireLogin(s.handleCalendarShare))
mux.HandleFunc("/ui/shares/addressbook", s.requireLogin(s.handleAddressBookShare))
mux.HandleFunc("/login", s.handleLogin)
mux.HandleFunc("/logout", s.handleLogout)
mux.HandleFunc("/", s.requireLogin(s.handleDashboard))
mux.HandleFunc("/shares/calendar", s.requireLogin(s.handleCalendarShare))
mux.HandleFunc("/shares/addressbook", s.requireLogin(s.handleAddressBookShare))
return mux
}
@@ -88,7 +89,7 @@ func (s *Server) handleLogin(w http.ResponseWriter, r *http.Request) {
return
}
s.setSessionCookie(w, token)
http.Redirect(w, r, "/ui/", http.StatusSeeOther)
http.Redirect(w, r, "/web/", http.StatusSeeOther)
}
func (s *Server) handleLogout(w http.ResponseWriter, r *http.Request) {
@@ -96,5 +97,5 @@ func (s *Server) handleLogout(w http.ResponseWriter, r *http.Request) {
_ = s.dbase.DeleteSession(cookie.Value)
}
s.clearSessionCookie(w)
http.Redirect(w, r, "/ui/login", http.StatusSeeOther)
http.Redirect(w, r, "/web/login", http.StatusSeeOther)
}
+10 -10
View File
@@ -51,7 +51,7 @@ func newTestServer(t *testing.T) *Server {
func loginAs(t *testing.T, handler http.Handler, username, password string) *http.Cookie {
t.Helper()
form := url.Values{"username": {username}, "password": {password}}
req := httptest.NewRequest(http.MethodPost, "/ui/login", strings.NewReader(form.Encode()))
req := httptest.NewRequest(http.MethodPost, "/login", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
@@ -80,7 +80,7 @@ func TestLoginSuccessAndFailure(t *testing.T) {
// Wrong password.
form := url.Values{"username": {"alice"}, "password": {"wrong"}}
req := httptest.NewRequest(http.MethodPost, "/ui/login", strings.NewReader(form.Encode()))
req := httptest.NewRequest(http.MethodPost, "/login", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
@@ -96,15 +96,15 @@ func TestDashboardRequiresLogin(t *testing.T) {
s := newTestServer(t)
handler := s.Handler(emptyStaticFS{})
req := httptest.NewRequest(http.MethodGet, "/ui/", nil)
req := httptest.NewRequest(http.MethodGet, "/", nil)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
if rr.Code != http.StatusSeeOther {
t.Fatalf("expected redirect to login, got %d", rr.Code)
}
if loc := rr.Result().Header.Get("Location"); loc != "/ui/login" {
t.Fatalf("expected redirect to /ui/login, got %q", loc)
if loc := rr.Result().Header.Get("Location"); loc != "/web/login" {
t.Fatalf("expected redirect to /web/login, got %q", loc)
}
}
@@ -113,7 +113,7 @@ func TestDashboardShowsOwnResources(t *testing.T) {
handler := s.Handler(emptyStaticFS{})
cookie := loginAs(t, handler, "alice", "password")
req := httptest.NewRequest(http.MethodGet, "/ui/", nil)
req := httptest.NewRequest(http.MethodGet, "/", nil)
req.AddCookie(cookie)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
@@ -134,7 +134,7 @@ func TestShareUnshareCalendarFlow(t *testing.T) {
// Share alice's "work" calendar with bob, write access.
form := url.Values{"resource": {"work"}, "shared_with": {"bob"}, "permission": {"write"}}
req := httptest.NewRequest(http.MethodPost, "/ui/shares/calendar", strings.NewReader(form.Encode()))
req := httptest.NewRequest(http.MethodPost, "/shares/calendar", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.AddCookie(cookie)
rr := httptest.NewRecorder()
@@ -155,7 +155,7 @@ func TestShareUnshareCalendarFlow(t *testing.T) {
}
// Unshare — htmx v2 sends DELETE params as a URL query string.
req = httptest.NewRequest(http.MethodDelete, "/ui/shares/calendar?resource=work&shared_with=bob", nil)
req = httptest.NewRequest(http.MethodDelete, "/shares/calendar?resource=work&shared_with=bob", nil)
req.AddCookie(cookie)
rr = httptest.NewRecorder()
handler.ServeHTTP(rr, req)
@@ -182,7 +182,7 @@ func TestCannotShareResourceNotOwned(t *testing.T) {
// alice doesn't own "personal" (that's bob's calendar).
form := url.Values{"resource": {"personal"}, "shared_with": {"bob"}, "permission": {"write"}}
req := httptest.NewRequest(http.MethodPost, "/ui/shares/calendar", strings.NewReader(form.Encode()))
req := httptest.NewRequest(http.MethodPost, "/shares/calendar", strings.NewReader(form.Encode()))
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
req.AddCookie(cookie)
rr := httptest.NewRecorder()
@@ -198,7 +198,7 @@ func TestLogoutClearsSession(t *testing.T) {
handler := s.Handler(emptyStaticFS{})
cookie := loginAs(t, handler, "alice", "password")
req := httptest.NewRequest(http.MethodGet, "/ui/logout", nil)
req := httptest.NewRequest(http.MethodGet, "/logout", nil)
req.AddCookie(cookie)
rr := httptest.NewRecorder()
handler.ServeHTTP(rr, req)
+2 -2
View File
@@ -26,13 +26,13 @@ func (s *Server) requireLogin(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
cookie, err := r.Cookie(sessionCookieName)
if err != nil {
http.Redirect(w, r, "/ui/login", http.StatusSeeOther)
http.Redirect(w, r, "/web/login", http.StatusSeeOther)
return
}
username, err := s.dbase.SessionUser(cookie.Value)
if err != nil {
s.clearSessionCookie(w)
http.Redirect(w, r, "/ui/login", http.StatusSeeOther)
http.Redirect(w, r, "/web/login", http.StatusSeeOther)
return
}
ctx := context.WithValue(r.Context(), userCtxKey, username)
+1 -1
View File
@@ -10,7 +10,7 @@ import (
// handleCalendarShare handles POST (create/update share) and DELETE
// (revoke share) for the current user's calendars, mounted at
// /ui/shares/calendar. htmx sends the resource + shared_with (+ permission
// /shares/calendar. htmx sends the resource + shared_with (+ permission
// for POST) as form values and expects the updated resource card HTML
// back for an out-of-band swap.
func (s *Server) handleCalendarShare(w http.ResponseWriter, r *http.Request) {
+2 -2
View File
@@ -113,9 +113,9 @@ templ ResourceCardView(r ResourceCard) {
func shareEndpoint(kind string) string {
if kind == "calendar" {
return "/ui/shares/calendar"
return "/web/shares/calendar"
}
return "/ui/shares/addressbook"
return "/web/shares/addressbook"
}
func shareVals(resource, sharedWith string) string {
+2 -2
View File
@@ -361,9 +361,9 @@ func ResourceCardView(r ResourceCard) templ.Component {
func shareEndpoint(kind string) string {
if kind == "calendar" {
return "/ui/shares/calendar"
return "/web/shares/calendar"
}
return "/ui/shares/addressbook"
return "/web/shares/addressbook"
}
func shareVals(resource, sharedWith string) string {
+4 -4
View File
@@ -7,17 +7,17 @@ templ Layout(title string, username string) {
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>{ title } · nidus</title>
<link rel="stylesheet" href="/ui/static/app.css"/>
<script src="/ui/static/htmx.min.js" defer></script>
<link rel="stylesheet" href="/web/static/app.css"/>
<script src="/web/static/htmx.min.js" defer></script>
</head>
<body class="h-full text-gray-900">
<nav class="bg-white border-b border-gray-200">
<div class="max-w-4xl mx-auto px-4 py-3 flex items-center justify-between">
<a href="/ui/" class="font-semibold text-lg tracking-tight">nidus</a>
<a href="/web/" class="font-semibold text-lg tracking-tight">nidus</a>
if username != "" {
<div class="flex items-center gap-4 text-sm text-gray-600">
<span>{ username }</span>
<a href="/ui/logout" class="text-red-600 hover:underline">Logout</a>
<a href="/web/logout" class="text-red-600 hover:underline">Logout</a>
</div>
}
</div>
+2 -2
View File
@@ -42,7 +42,7 @@ func Layout(title string, username string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, " · nidus</title><link rel=\"stylesheet\" href=\"/ui/static/app.css\"><script src=\"/ui/static/htmx.min.js\" defer></script></head><body class=\"h-full text-gray-900\"><nav class=\"bg-white border-b border-gray-200\"><div class=\"max-w-4xl mx-auto px-4 py-3 flex items-center justify-between\"><a href=\"/ui/\" class=\"font-semibold text-lg tracking-tight\">nidus</a> ")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 2, " · nidus</title><link rel=\"stylesheet\" href=\"/web/static/app.css\"><script src=\"/web/static/htmx.min.js\" defer></script></head><body class=\"h-full text-gray-900\"><nav class=\"bg-white border-b border-gray-200\"><div class=\"max-w-4xl mx-auto px-4 py-3 flex items-center justify-between\"><a href=\"/web/\" class=\"font-semibold text-lg tracking-tight\">nidus</a> ")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -60,7 +60,7 @@ func Layout(title string, username string) templ.Component {
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</span> <a href=\"/ui/logout\" class=\"text-red-600 hover:underline\">Logout</a></div>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "</span> <a href=\"/web/logout\" class=\"text-red-600 hover:underline\">Logout</a></div>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
+2 -2
View File
@@ -7,7 +7,7 @@ templ Login(errorMsg string) {
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1.0"/>
<title>Login · nidus</title>
<link rel="stylesheet" href="/ui/static/app.css"/>
<link rel="stylesheet" href="/web/static/app.css"/>
</head>
<body class="h-full flex items-center justify-center">
<div class="w-full max-w-sm bg-white p-8 rounded-lg shadow-sm border border-gray-200">
@@ -15,7 +15,7 @@ templ Login(errorMsg string) {
if errorMsg != "" {
<p class="mb-4 text-sm text-red-600 bg-red-50 border border-red-200 rounded px-3 py-2">{ errorMsg }</p>
}
<form method="POST" action="/ui/login" class="space-y-4">
<form method="POST" action="/web/login" class="space-y-4">
<div>
<label for="username" class="block text-sm font-medium text-gray-700">Username</label>
<input id="username" name="username" type="text" required autofocus
+2 -2
View File
@@ -29,7 +29,7 @@ func Login(errorMsg string) templ.Component {
templ_7745c5c3_Var1 = templ.NopComponent
}
ctx = templ.ClearChildren(ctx)
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<!doctype html><html lang=\"en\" class=\"h-full bg-gray-50\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Login · nidus</title><link rel=\"stylesheet\" href=\"/ui/static/app.css\"></head><body class=\"h-full flex items-center justify-center\"><div class=\"w-full max-w-sm bg-white p-8 rounded-lg shadow-sm border border-gray-200\"><h1 class=\"text-xl font-semibold mb-6 text-center\">nidus</h1>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 1, "<!doctype html><html lang=\"en\" class=\"h-full bg-gray-50\"><head><meta charset=\"UTF-8\"><meta name=\"viewport\" content=\"width=device-width, initial-scale=1.0\"><title>Login · nidus</title><link rel=\"stylesheet\" href=\"/web/static/app.css\"></head><body class=\"h-full flex items-center justify-center\"><div class=\"w-full max-w-sm bg-white p-8 rounded-lg shadow-sm border border-gray-200\"><h1 class=\"text-xl font-semibold mb-6 text-center\">nidus</h1>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}
@@ -52,7 +52,7 @@ func Login(errorMsg string) templ.Component {
return templ_7745c5c3_Err
}
}
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<form method=\"POST\" action=\"/ui/login\" class=\"space-y-4\"><div><label for=\"username\" class=\"block text-sm font-medium text-gray-700\">Username</label> <input id=\"username\" name=\"username\" type=\"text\" required autofocus class=\"mt-1 block w-full rounded-md border-gray-300 border px-3 py-2 shadow-sm focus:border-indigo-500 focus:ring-indigo-500\"></div><div><label for=\"password\" class=\"block text-sm font-medium text-gray-700\">Password</label> <input id=\"password\" name=\"password\" type=\"password\" required class=\"mt-1 block w-full rounded-md border-gray-300 border px-3 py-2 shadow-sm focus:border-indigo-500 focus:ring-indigo-500\"></div><button type=\"submit\" class=\"w-full bg-indigo-600 text-white rounded-md py-2 font-medium hover:bg-indigo-700\">Sign in</button></form></div></body></html>")
templ_7745c5c3_Err = templruntime.WriteString(templ_7745c5c3_Buffer, 4, "<form method=\"POST\" action=\"/web/login\" class=\"space-y-4\"><div><label for=\"username\" class=\"block text-sm font-medium text-gray-700\">Username</label> <input id=\"username\" name=\"username\" type=\"text\" required autofocus class=\"mt-1 block w-full rounded-md border-gray-300 border px-3 py-2 shadow-sm focus:border-indigo-500 focus:ring-indigo-500\"></div><div><label for=\"password\" class=\"block text-sm font-medium text-gray-700\">Password</label> <input id=\"password\" name=\"password\" type=\"password\" required class=\"mt-1 block w-full rounded-md border-gray-300 border px-3 py-2 shadow-sm focus:border-indigo-500 focus:ring-indigo-500\"></div><button type=\"submit\" class=\"w-full bg-indigo-600 text-white rounded-md py-2 font-medium hover:bg-indigo-700\">Sign in</button></form></div></body></html>")
if templ_7745c5c3_Err != nil {
return templ_7745c5c3_Err
}