feat: add rest.WithCustomCors to let caller customize the response (#1274)
This commit is contained in:
@@ -99,8 +99,17 @@ func ToMiddleware(handler func(next http.Handler) http.Handler) Middleware {
|
||||
// WithCors returns a func to enable CORS for given origin, or default to all origins (*).
|
||||
func WithCors(origin ...string) RunOption {
|
||||
return func(server *Server) {
|
||||
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(origin...))
|
||||
server.Use(cors.Middleware(origin...))
|
||||
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(nil, origin...))
|
||||
server.Use(cors.Middleware(nil, origin...))
|
||||
}
|
||||
}
|
||||
|
||||
// WithCustomCors returns a func to enable CORS for given origin, or default to all origins (*),
|
||||
// fn lets caller customizing the response.
|
||||
func WithCustomCors(fn func(http.ResponseWriter), origin ...string) RunOption {
|
||||
return func(server *Server) {
|
||||
server.router.SetNotAllowedHandler(cors.NotAllowedHandler(fn, origin...))
|
||||
server.Use(cors.Middleware(fn, origin...))
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user