-
Notifications
You must be signed in to change notification settings - Fork 151
/
handler.go
38 lines (30 loc) · 942 Bytes
/
handler.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package server
import (
"context"
"fmt"
"net/http"
"github.com/go-logr/logr"
"github.com/grpc-ecosystem/grpc-gateway/v2/runtime"
core "github.com/weaveworks/weave-gitops/core/server"
"github.com/weaveworks/weave-gitops/pkg/server/auth"
"github.com/weaveworks/weave-gitops/pkg/server/middleware"
)
var (
PublicRoutes = []string{
"/v1/featureflags",
}
)
type Config struct {
AppConfig *ApplicationsConfig
AppOptions []ApplicationsOption
CoreServerConfig core.CoreServerConfig
AuthServer *auth.AuthServer
}
func NewHandlers(ctx context.Context, log logr.Logger, cfg *Config) (http.Handler, error) {
mux := runtime.NewServeMux(middleware.WithGrpcErrorLogging(log))
if err := core.Hydrate(ctx, mux, cfg.CoreServerConfig); err != nil {
return nil, fmt.Errorf("could not start up core servers: %w", err)
}
httpHandler := auth.WithAPIAuth(mux, cfg.AuthServer, PublicRoutes)
return httpHandler, nil
}