-
Notifications
You must be signed in to change notification settings - Fork 482
/
cors_interceptor.go
49 lines (43 loc) · 983 Bytes
/
cors_interceptor.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
39
40
41
42
43
44
45
46
47
48
49
package middleware
import (
"net/http"
"github.com/rs/cors"
http_utils "github.com/zitadel/zitadel/internal/api/http"
)
var (
DefaultCORSOptions = cors.Options{
AllowCredentials: true,
AllowedHeaders: []string{
http_utils.Origin,
http_utils.ContentType,
http_utils.Accept,
http_utils.AcceptLanguage,
http_utils.Authorization,
http_utils.ZitadelOrgID,
http_utils.XUserAgent,
http_utils.XGrpcWeb,
},
AllowedMethods: []string{
http.MethodOptions,
http.MethodGet,
http.MethodHead,
http.MethodPost,
http.MethodPut,
http.MethodPatch,
http.MethodDelete,
},
ExposedHeaders: []string{
http_utils.Location,
http_utils.ContentLength,
},
AllowOriginFunc: func(_ string) bool {
return true
},
}
)
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)
}