package api import ( "net/http" "strings" dashboard "bat-api/web" ) const adminDashboardPath = "/admin/dashboard" var adminDashboardFileServer = http.FileServer(http.FS(dashboard.Assets)) func (s *Server) handleAdminDashboard(w http.ResponseWriter, r *http.Request) { if r.Method != http.MethodGet && r.Method != http.MethodHead { writeErrorJSON(w, http.StatusMethodNotAllowed, "method_not_allowed", "method not allowed") return } w.Header().Set("Cache-Control", "no-store") if r.URL.Path == adminDashboardPath { http.Redirect(w, r, adminDashboardPath+"/", http.StatusMovedPermanently) return } if !strings.HasPrefix(r.URL.Path, adminDashboardPath+"/") { http.NotFound(w, r) return } http.StripPrefix(adminDashboardPath+"/", adminDashboardFileServer).ServeHTTP(w, r) } func dashboardAuthExemptPaths() []string { return []string{adminDashboardPath, adminDashboardPath + "/"} } func isAdminDashboardPath(path string) bool { return path == adminDashboardPath || strings.HasPrefix(path, adminDashboardPath+"/") }