Files
homelab-frontend/internal/server/router.go
T
Admin Bot b8f95506ca feat: add Temporal config and update routing with memory service integration
- Add TemporalConfig struct to internal/config
- Update gateway config with Temporal frontend service (port 7233)
- Update router with memory service adapter support
- Add config.local.yaml with memory service configuration
- Encrypt production config with SOPS (AES256_GCM)
- Support X-Service header routing pattern for service discovery
- Keep legacy path-based routes with deprecation warnings
- All 5 adapters preserved: workflow, memory, sqs, s3, iam
2026-09-13 10:56:18 +09:00

72 lines
2.3 KiB
Go

package server
import (
"net/http"
"forgejo.riotpiao.com/rock/homelab-frontend/internal/serviceadapter"
)
// Router implements an HTTP handler that routes health endpoints,
// ServiceAdapter X-Service requests, Temporal workflow endpoints,
// and other requests to upstream handlers.
type Router struct {
healthChecker *HealthChecker
dispatcher *serviceadapter.Dispatcher
temporalHandler http.Handler
upstreamHandler http.Handler
}
// NewRouter creates a new router with health endpoints.
// Health endpoints (/healthz and /readyz) are handled locally.
// X-Service requests are dispatched via ServiceAdapter CRD.
// Temporal endpoints (/workflow*) are routed to temporalHandler.
// All other paths are passed to the upstream handler.
func NewRouter(healthChecker *HealthChecker, dispatcher *serviceadapter.Dispatcher, temporalHandler http.Handler, upstreamHandler http.Handler) *Router {
return &Router{
healthChecker: healthChecker,
dispatcher: dispatcher,
temporalHandler: temporalHandler,
upstreamHandler: upstreamHandler,
}
}
// ServeHTTP implements http.Handler.
// Priority order:
// 1. /healthz and /readyz to health handlers
// 2. X-Service header to ServiceAdapter dispatcher (phase 8) - PREFERRED routing method
// 3. /workflow* to temporal handler - DEPRECATED: use X-Service: workflow instead
// 4. All other paths to upstream handler (phase 0-7)
func (r *Router) ServeHTTP(w http.ResponseWriter, req *http.Request) {
// Health endpoints first
switch req.URL.Path {
case "/healthz":
LivenessHandler(r.healthChecker)(w, req)
return
case "/readyz":
ReadinessHandler(r.healthChecker)(w, req)
return
}
// X-Service (ServiceAdapter) routing - checked before path-based routing
// PREFERRED: All service routing should use X-Service header pattern for consistency,
// auth enforcement, and resource-based access control.
if req.Header.Get("X-Service") != "" {
if r.dispatcher != nil {
r.dispatcher.Dispatch(w, req)
return
}
}
// Workflow endpoints
// DEPRECATED: Path-based /workflow routing is legacy.
// New clients should use X-Service: workflow header instead for consistent auth.
switch req.URL.Path {
case "/workflow", "/workflow/health", "/workflow/metrics":
r.temporalHandler.ServeHTTP(w, req)
return
}
// Default: upstream handler (all other paths)
r.upstreamHandler.ServeHTTP(w, req)
}