package api import ( "log/slog" "net/http" "sort" ) // listProxyRoutes handles GET /api/proxies. // Returns proxy routes from both Docker instances and static sites, // merged and sorted by domain. func (s *Server) listProxyRoutes(w http.ResponseWriter, r *http.Request) { settings, err := s.store.GetSettings() if err != nil { slog.Error("failed to get settings for proxy routes", "error", err) respondError(w, http.StatusInternalServerError, "internal server error") return } instanceRoutes, err := s.store.ListProxyRoutes(settings.Domain) if err != nil { slog.Error("failed to list instance proxy routes", "error", err) respondError(w, http.StatusInternalServerError, "internal server error") return } siteRoutes, err := s.store.ListStaticSiteProxyRoutes(settings.Domain) if err != nil { slog.Error("failed to list static site proxy routes", "error", err) respondError(w, http.StatusInternalServerError, "internal server error") return } routes := append(instanceRoutes, siteRoutes...) sort.SliceStable(routes, func(i, j int) bool { if routes[i].Domain == routes[j].Domain { return routes[i].ProjectName < routes[j].ProjectName } return routes[i].Domain < routes[j].Domain }) respondJSON(w, http.StatusOK, routes) }