High-performance browser automation bridge and multi-instance orchestrator with advanced stealth injection and real-time dashboard.
refactor: centralise shorthand route registration across strategies
Data872e064c0a91
diff --git a/internal/strategy/autorestart/autorestart.go b/internal/strategy/autorestart/autorestart.goindex d008b48b..4778f945 100644--- a/internal/strategy/autorestart/autorestart.go+++ b/internal/strategy/autorestart/autorestart.go@@ -173,35 +173,7 @@ func (s *Strategy) Stop() error {// RegisterRoutes adds shorthand endpoints that proxy to the managed instance.func (s *Strategy) RegisterRoutes(mux *http.ServeMux) {s.orch.RegisterHandlers(mux)-- shorthandRoutes := []string{- "GET /snapshot", "GET /screenshot", "GET /text", "GET /pdf", "POST /pdf",- "GET /console", "POST /console/clear",- "GET /errors", "POST /errors/clear",- "GET /clipboard/read", "POST /clipboard/write", "POST /clipboard/copy", "GET /clipboard/paste",- "GET /network", "GET /network/stream", "GET /network/export", "GET /network/export/stream", "GET /network/{requestId}", "POST /network/clear",- "POST /navigate", "POST /back", "POST /forward", "POST /reload",- "POST /action", "POST /actions",- "POST /dialog",- "POST /wait",- "POST /tab", "POST /tab/lock", "POST /tab/unlock",- "GET /cookies", "POST /cookies",- "GET /stealth/status", "POST /fingerprint/rotate",- "POST /find",- "POST /cache/clear", "GET /cache/status",- "GET /solvers",- "POST /solve", "POST /solve/{name}",- }- for _, route := range shorthandRoutes {- mux.HandleFunc(route, s.proxyToManaged)- }- strategy.RegisterCapabilityRoute(mux, "POST /evaluate", s.orch.AllowsEvaluate(), "evaluate", "security.allowEvaluate", "evaluate_disabled", s.proxyToManaged)- strategy.RegisterCapabilityRoute(mux, "GET /download", s.orch.AllowsDownload(), "download", "security.allowDownload", "download_disabled", s.proxyToManaged)- strategy.RegisterCapabilityRoute(mux, "POST /upload", s.orch.AllowsUpload(), "upload", "security.allowUpload", "upload_disabled", s.proxyToManaged)- strategy.RegisterCapabilityRoute(mux, "GET /screencast", s.orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", s.proxyToManaged)- strategy.RegisterCapabilityRoute(mux, "GET /screencast/tabs", s.orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", s.proxyToManaged)- strategy.RegisterCapabilityRoute(mux, "POST /macro", s.orch.AllowsMacro(), "macro", "security.allowMacro", "macro_disabled", s.proxyToManaged)-+ strategy.RegisterShorthandRoutes(mux, s.orch, s.proxyToManaged)mux.HandleFunc("GET /tabs", s.handleTabs)mux.HandleFunc("GET "+s.config.StatusPath, s.handleStatus)}diff --git a/internal/strategy/explicit/explicit.go b/internal/strategy/explicit/explicit.goindex 68c8598f..900a8a5e 100644--- a/internal/strategy/explicit/explicit.go+++ b/internal/strategy/explicit/explicit.go@@ -38,35 +38,7 @@ func (s *Strategy) Stop() error { return nil }// RegisterRoutes adds all orchestrator routes plus shorthand proxy endpoints.func (s *Strategy) RegisterRoutes(mux *http.ServeMux) {s.orch.RegisterHandlers(mux)-- // Shorthand endpoints proxy to first running instance.- shorthandRoutes := []string{- "GET /snapshot", "GET /screenshot", "GET /text", "GET /pdf", "POST /pdf",- "GET /console", "POST /console/clear",- "GET /errors", "POST /errors/clear",- "POST /navigate", "POST /back", "POST /forward", "POST /reload",- "POST /action", "POST /actions",- "POST /wait",- "POST /tab", "POST /tab/lock", "POST /tab/unlock",- "GET /cookies", "POST /cookies",- "GET /stealth/status", "POST /fingerprint/rotate",- "POST /find",- "POST /cache/clear", "GET /cache/status",- "GET /solvers",- "POST /solve", "POST /solve/{name}",- "GET /network", "GET /network/stream", "GET /network/export", "GET /network/export/stream", "GET /network/{requestId}", "POST /network/clear",- }- for _, route := range shorthandRoutes {- mux.HandleFunc(route, s.proxyToFirst)- }- strategy.RegisterCapabilityRoute(mux, "POST /evaluate", s.orch.AllowsEvaluate(), "evaluate", "security.allowEvaluate", "evaluate_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "GET /download", s.orch.AllowsDownload(), "download", "security.allowDownload", "download_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "POST /upload", s.orch.AllowsUpload(), "upload", "security.allowUpload", "upload_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "GET /screencast", s.orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "GET /screencast/tabs", s.orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "POST /macro", s.orch.AllowsMacro(), "macro", "security.allowMacro", "macro_disabled", s.proxyToFirst)-- // /tabs returns empty list when no instances running.+ strategy.RegisterShorthandRoutes(mux, s.orch, s.proxyToFirst)mux.HandleFunc("GET /tabs", s.handleTabs)}diff --git a/internal/strategy/noinstance/noinstance.go b/internal/strategy/noinstance/noinstance.goindex 04545c6b..cbf4b958 100644--- a/internal/strategy/noinstance/noinstance.go+++ b/internal/strategy/noinstance/noinstance.go@@ -34,34 +34,8 @@ func (s *Strategy) Start(_ context.Context) error { return nil }func (s *Strategy) Stop() error { return nil }func (s *Strategy) RegisterRoutes(mux *http.ServeMux) {- // Register orchestrator handlers without local launch endpointss.orch.RegisterHandlersNoLaunch(mux)-- // Shorthand endpoints proxy to first running (remote) instance- shorthandRoutes := []string{- "GET /snapshot", "GET /screenshot", "GET /text", "GET /pdf", "POST /pdf",- "POST /navigate", "POST /back", "POST /forward", "POST /reload",- "POST /action", "POST /actions",- "POST /wait",- "POST /tab", "POST /tab/lock", "POST /tab/unlock",- "GET /cookies", "POST /cookies",- "GET /stealth/status", "POST /fingerprint/rotate",- "POST /find",- "POST /cache/clear", "GET /cache/status",- "GET /solvers",- "POST /solve", "POST /solve/{name}",- "GET /network", "GET /network/stream", "GET /network/export", "GET /network/export/stream", "GET /network/{requestId}", "POST /network/clear",- }- for _, route := range shorthandRoutes {- mux.HandleFunc(route, s.proxyToFirst)- }- strategy.RegisterCapabilityRoute(mux, "POST /evaluate", s.orch.AllowsEvaluate(), "evaluate", "security.allowEvaluate", "evaluate_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "GET /download", s.orch.AllowsDownload(), "download", "security.allowDownload", "download_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "POST /upload", s.orch.AllowsUpload(), "upload", "security.allowUpload", "upload_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "GET /screencast", s.orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "GET /screencast/tabs", s.orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "POST /macro", s.orch.AllowsMacro(), "macro", "security.allowMacro", "macro_disabled", s.proxyToFirst)-+ strategy.RegisterShorthandRoutes(mux, s.orch, s.proxyToFirst)mux.HandleFunc("GET /tabs", s.handleTabs)}diff --git a/internal/strategy/routes.go b/internal/strategy/routes.gonew file mode 100644index 00000000..29a3092e--- /dev/null+++ b/internal/strategy/routes.go@@ -0,0 +1,46 @@+package strategy++import (+ "net/http"++ "github.com/pinchtab/pinchtab/internal/orchestrator"+)++// ShorthandRoutes are the proxy routes that every strategy registers.+// They forward to the first running instance (or the managed instance).+// Defined once here to avoid duplication across strategy implementations.+var ShorthandRoutes = []string{+ "GET /snapshot", "GET /screenshot", "GET /text", "GET /pdf", "POST /pdf",+ "GET /console", "POST /console/clear",+ "GET /errors", "POST /errors/clear",+ "GET /clipboard/read", "POST /clipboard/write", "POST /clipboard/copy", "GET /clipboard/paste",+ "GET /network", "GET /network/stream", "GET /network/export", "GET /network/export/stream", "GET /network/{requestId}", "POST /network/clear",+ "POST /navigate", "POST /back", "POST /forward", "POST /reload",+ "POST /action", "POST /actions",+ "POST /dialog",+ "POST /wait",+ "POST /tab", "POST /tab/lock", "POST /tab/unlock",+ "GET /cookies", "POST /cookies",+ "GET /stealth/status", "POST /fingerprint/rotate",+ "POST /find",+ "POST /cache/clear", "GET /cache/status",+ "GET /solvers",+ "POST /solve", "POST /solve/{name}",+}++// RegisterShorthandRoutes registers all shorthand proxy routes on the mux,+// binding them to the given handler. It also registers capability-gated+// routes (evaluate, download, upload, screencast, macro) using the+// orchestrator's security settings.+func RegisterShorthandRoutes(mux *http.ServeMux, orch *orchestrator.Orchestrator, handler http.HandlerFunc) {+ for _, route := range ShorthandRoutes {+ mux.HandleFunc(route, handler)+ }++ RegisterCapabilityRoute(mux, "POST /evaluate", orch.AllowsEvaluate(), "evaluate", "security.allowEvaluate", "evaluate_disabled", handler)+ RegisterCapabilityRoute(mux, "GET /download", orch.AllowsDownload(), "download", "security.allowDownload", "download_disabled", handler)+ RegisterCapabilityRoute(mux, "POST /upload", orch.AllowsUpload(), "upload", "security.allowUpload", "upload_disabled", handler)+ RegisterCapabilityRoute(mux, "GET /screencast", orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", handler)+ RegisterCapabilityRoute(mux, "GET /screencast/tabs", orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", handler)+ RegisterCapabilityRoute(mux, "POST /macro", orch.AllowsMacro(), "macro", "security.allowMacro", "macro_disabled", handler)+}diff --git a/internal/strategy/simple/simple.go b/internal/strategy/simple/simple.goindex 3c1ca928..e2738209 100644--- a/internal/strategy/simple/simple.go+++ b/internal/strategy/simple/simple.go@@ -44,38 +44,8 @@ func (s *Strategy) Stop() error { return nil }// RegisterRoutes adds shorthand endpoints that proxy to the first running instance.func (s *Strategy) RegisterRoutes(mux *http.ServeMux) {- // Register orchestrator's instance/profile/tab-specific routes.s.orch.RegisterHandlers(mux)-- // Shorthand endpoints — all proxy to first running instance.- shorthandRoutes := []string{- "GET /snapshot", "GET /screenshot", "GET /text", "GET /pdf", "POST /pdf",- "GET /console", "POST /console/clear",- "GET /errors", "POST /errors/clear",- "GET /clipboard/read", "POST /clipboard/write", "POST /clipboard/copy", "GET /clipboard/paste",- "GET /network", "GET /network/stream", "GET /network/export", "GET /network/export/stream", "GET /network/{requestId}", "POST /network/clear",- "POST /navigate", "POST /back", "POST /forward", "POST /reload",- "POST /action", "POST /actions",- "POST /dialog",- "POST /wait",- "POST /tab", "POST /tab/lock", "POST /tab/unlock",- "GET /cookies", "POST /cookies",- "GET /stealth/status", "POST /fingerprint/rotate",- "POST /find",- "POST /cache/clear", "GET /cache/status",- "GET /solvers",- "POST /solve", "POST /solve/{name}",- }- for _, route := range shorthandRoutes {- mux.HandleFunc(route, s.proxyToFirst)- }- strategy.RegisterCapabilityRoute(mux, "POST /evaluate", s.orch.AllowsEvaluate(), "evaluate", "security.allowEvaluate", "evaluate_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "GET /download", s.orch.AllowsDownload(), "download", "security.allowDownload", "download_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "POST /upload", s.orch.AllowsUpload(), "upload", "security.allowUpload", "upload_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "GET /screencast", s.orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "GET /screencast/tabs", s.orch.AllowsScreencast(), "screencast", "security.allowScreencast", "screencast_disabled", s.proxyToFirst)- strategy.RegisterCapabilityRoute(mux, "POST /macro", s.orch.AllowsMacro(), "macro", "security.allowMacro", "macro_disabled", s.proxyToFirst)-+ strategy.RegisterShorthandRoutes(mux, s.orch, s.proxyToFirst)mux.HandleFunc("GET /tabs", s.handleTabs)}