Fix 404s: serve UI templates/static from configurable ui-root, not CWD
The web UI 404'd in production because templates/static were loaded
via relative paths ("internal/ui/templates", "internal/ui/static"),
which only resolved when running from the repo checkout. systemd sets
WorkingDirectory=/var/lib/wireguard-ui-multi, so those paths never
existed there.
Add a -ui-root flag (default /usr/local/share/wireguard-ui-multi/ui),
have install.sh copy internal/ui there, and resolve templates/static
paths through it instead of hardcoded relative strings.
Also add release-binary fast path to bootstrap.sh (falls back to
source build with CGO_ENABLED=0/-trimpath if no release exists yet),
and document real hardware/build-RAM requirements in the README.
Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5
parent
b2b6b82f58
commit
41894e67c6
+13
-2
@@ -3,6 +3,7 @@ package api
|
||||
import (
|
||||
"log/slog"
|
||||
"net/http"
|
||||
"path/filepath"
|
||||
|
||||
"gitea.perlbach24.de/scripte/wireguard-ui-multi/internal/database"
|
||||
"gitea.perlbach24.de/scripte/wireguard-ui-multi/internal/server"
|
||||
@@ -15,18 +16,28 @@ type API struct {
|
||||
sessions *SessionStore
|
||||
log *slog.Logger
|
||||
lanIface string
|
||||
uiRoot string
|
||||
}
|
||||
|
||||
func New(db *database.DB, log *slog.Logger, lanIface string) *API {
|
||||
func New(db *database.DB, log *slog.Logger, lanIface, uiRoot string) *API {
|
||||
return &API{
|
||||
db: db,
|
||||
store: server.NewStore(db),
|
||||
sessions: NewSessionStore(),
|
||||
log: log,
|
||||
lanIface: lanIface,
|
||||
uiRoot: uiRoot,
|
||||
}
|
||||
}
|
||||
|
||||
func (a *API) templatesDir() string {
|
||||
return filepath.Join(a.uiRoot, "templates")
|
||||
}
|
||||
|
||||
func (a *API) staticDir() string {
|
||||
return filepath.Join(a.uiRoot, "static")
|
||||
}
|
||||
|
||||
// Routes builds the full HTTP handler tree (API + UI), using Go 1.22 mux patterns.
|
||||
func (a *API) Routes() http.Handler {
|
||||
mux := http.NewServeMux()
|
||||
@@ -57,7 +68,7 @@ func (a *API) Routes() http.Handler {
|
||||
mux.HandleFunc("GET /", a.handleDashboard)
|
||||
mux.HandleFunc("GET /login", a.handleLoginPage)
|
||||
mux.HandleFunc("GET /servers/{id}", a.handleServerPage)
|
||||
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir("internal/ui/static"))))
|
||||
mux.Handle("GET /static/", http.StripPrefix("/static/", http.FileServer(http.Dir(a.staticDir()))))
|
||||
|
||||
return a.logMiddleware(mux)
|
||||
}
|
||||
|
||||
@@ -4,8 +4,6 @@ import (
|
||||
"net/http"
|
||||
)
|
||||
|
||||
const templatesDir = "internal/ui/templates"
|
||||
|
||||
// hasSession reports whether the request carries a valid, non-expired session cookie.
|
||||
func (a *API) hasSession(r *http.Request) bool {
|
||||
c, err := r.Cookie(sessionCookieName)
|
||||
@@ -21,7 +19,7 @@ func (a *API) handleDashboard(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/login", http.StatusFound)
|
||||
return
|
||||
}
|
||||
http.ServeFile(w, r, templatesDir+"/dashboard.html")
|
||||
http.ServeFile(w, r, a.templatesDir()+"/dashboard.html")
|
||||
}
|
||||
|
||||
func (a *API) handleLoginPage(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -29,7 +27,7 @@ func (a *API) handleLoginPage(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/", http.StatusFound)
|
||||
return
|
||||
}
|
||||
http.ServeFile(w, r, templatesDir+"/login.html")
|
||||
http.ServeFile(w, r, a.templatesDir()+"/login.html")
|
||||
}
|
||||
|
||||
func (a *API) handleServerPage(w http.ResponseWriter, r *http.Request) {
|
||||
@@ -37,5 +35,5 @@ func (a *API) handleServerPage(w http.ResponseWriter, r *http.Request) {
|
||||
http.Redirect(w, r, "/login", http.StatusFound)
|
||||
return
|
||||
}
|
||||
http.ServeFile(w, r, templatesDir+"/server.html")
|
||||
http.ServeFile(w, r, a.templatesDir()+"/server.html")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user