feat: redirect / to the web UI
ci/woodpecker/pr/pre-commit Pipeline was successful
ci/woodpecker/pr/test Pipeline was successful
ci/woodpecker/pr/build Pipeline was successful

The web UI is served under /ui, but hitting the bare domain returned the
API's JSON identity blob, so browsers never landed on the app. The root
now redirects to /ui/; the identity blob (name + version) moves to
/version so monitoring can still read it.

- redirect GET / to /ui/ (302)
- serve the former root JSON at /version
- update the server test to assert the redirect and the /version payload
This commit is contained in:
2026-07-03 14:53:33 +10:00
parent 787de74b3d
commit 0a4d294684
2 changed files with 28 additions and 2 deletions
+7
View File
@@ -95,6 +95,7 @@ func (s *Server) routes() chi.Router {
r.Get("/health", s.handleHealth)
r.Get("/", s.handleRoot)
r.Get("/version", s.handleVersion)
proxyHandler := v1.NewProxyHandler(s.engine, s.virtEngine, s.db, s.store, s.localHandler)
r.Mount("/api/v1", proxyHandler.Routes())
@@ -143,7 +144,13 @@ func (s *Server) handleHealth(w http.ResponseWriter, r *http.Request) {
fmt.Fprint(w, `{"status":"ok"}`)
}
// handleRoot sends browsers landing on the bare domain to the web UI, which is
// served under /ui. The service identity that used to live here is at /version.
func (s *Server) handleRoot(w http.ResponseWriter, r *http.Request) {
http.Redirect(w, r, "/ui/", http.StatusFound)
}
func (s *Server) handleVersion(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Content-Type", "application/json")
w.WriteHeader(http.StatusOK)
fmt.Fprintf(w, `{"name":"artifactapi","version":"%s"}`, s.version)