mirror of
https://github.com/zitadel/zitadel.git
synced 2025-08-12 03:37:34 +00:00
add tracing and refactor some api pkgs
This commit is contained in:
47
internal/api/http/middleware/cors_interceptor.go
Normal file
47
internal/api/http/middleware/cors_interceptor.go
Normal file
@@ -0,0 +1,47 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/rs/cors"
|
||||
|
||||
"github.com/caos/zitadel/internal/api"
|
||||
)
|
||||
|
||||
var (
|
||||
DefaultCORSOptions = cors.Options{
|
||||
AllowCredentials: true,
|
||||
AllowedHeaders: []string{
|
||||
api.Origin,
|
||||
api.ContentType,
|
||||
api.Accept,
|
||||
api.AcceptLanguage,
|
||||
api.Authorization,
|
||||
api.ZitadelOrgID,
|
||||
"x-grpc-web", //TODO: needed
|
||||
},
|
||||
AllowedMethods: []string{
|
||||
http.MethodOptions,
|
||||
http.MethodGet,
|
||||
http.MethodHead,
|
||||
http.MethodPost,
|
||||
http.MethodPut,
|
||||
http.MethodPatch,
|
||||
http.MethodDelete,
|
||||
},
|
||||
ExposedHeaders: []string{
|
||||
api.Location,
|
||||
},
|
||||
AllowedOrigins: []string{
|
||||
"http://localhost:*",
|
||||
},
|
||||
}
|
||||
)
|
||||
|
||||
func CORSInterceptorOpts(opts cors.Options, h http.Handler) http.Handler {
|
||||
return cors.New(opts).Handler(h)
|
||||
}
|
||||
|
||||
func CORSInterceptor(h http.Handler) http.Handler {
|
||||
return CORSInterceptorOpts(DefaultCORSOptions, h)
|
||||
}
|
12
internal/api/http/middleware/trace_interceptor.go
Normal file
12
internal/api/http/middleware/trace_interceptor.go
Normal file
@@ -0,0 +1,12 @@
|
||||
package middleware
|
||||
|
||||
import (
|
||||
"net/http"
|
||||
|
||||
"github.com/caos/zitadel/internal/api"
|
||||
"github.com/caos/zitadel/internal/tracing"
|
||||
)
|
||||
|
||||
func DefaultTraceHandler(handler http.Handler) http.Handler {
|
||||
return tracing.TraceHandler(handler, api.Probes...)
|
||||
}
|
Reference in New Issue
Block a user