mirror of
https://github.com/kataras/iris.git
synced 2025-01-23 18:51:03 +01:00
74872c62c7
Former-commit-id: dbd0866a65f680b4d871768053fc42a795b03a62
34 lines
1.1 KiB
Go
34 lines
1.1 KiB
Go
package cors
|
|
|
|
// +------------------------------------------------------------+
|
|
// | Cors wrapper usage |
|
|
// +------------------------------------------------------------+
|
|
//
|
|
// import "gopkg.in/kataras/iris.v6/adaptors/cors"
|
|
//
|
|
// app := iris.New()
|
|
// app.Adapt(cors.New(cors.Options{})))
|
|
|
|
import (
|
|
"github.com/rs/cors"
|
|
"gopkg.in/kataras/iris.v6"
|
|
)
|
|
|
|
// Options is a configuration container to setup the CORS.
|
|
type Options cors.Options
|
|
|
|
// New returns a new cors router wrapper policy
|
|
// with the provided options.
|
|
//
|
|
// create a new cors middleware, pass its options (casted)
|
|
// and pass the .ServeHTTP(w,r,next(http.HandlerFunc)) as the wrapper
|
|
// for the whole iris' Router
|
|
//
|
|
// Unlike the cors middleware, this wrapper wraps the entirely router,
|
|
// it cannot be registered to specific routes. It works better and all Options are working.
|
|
func New(opts Options) iris.RouterWrapperPolicy { return cors.New(cors.Options(opts)).ServeHTTP }
|
|
|
|
// Default returns a New cors wrapper with the default options
|
|
// accepting GET and POST requests and allowing all origins.
|
|
func Default() iris.RouterWrapperPolicy { return New(Options{}) }
|