mirror of
https://github.com/kataras/iris.git
synced 2025-02-09 02:34:55 +01:00
Add an example for the cors adaptor (router wrapper)
Former-commit-id: dbd0866a65f680b4d871768053fc42a795b03a62
This commit is contained in:
parent
30f9bd364e
commit
74872c62c7
40
adaptors/cors/_example/main.go
Normal file
40
adaptors/cors/_example/main.go
Normal file
|
@ -0,0 +1,40 @@
|
||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"gopkg.in/kataras/iris.v6"
|
||||||
|
"gopkg.in/kataras/iris.v6/adaptors/cors"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
|
||||||
|
app := iris.New()
|
||||||
|
app.Adapt(iris.DevLogger())
|
||||||
|
crs := cors.New(cors.Options{
|
||||||
|
AllowedOrigins: []string{"*"},
|
||||||
|
AllowCredentials: true,
|
||||||
|
})
|
||||||
|
|
||||||
|
app.Adapt(crs) // this line should be added
|
||||||
|
// adaptor supports cors allowed methods, middleware does not.
|
||||||
|
|
||||||
|
// if you want per-route-only cors
|
||||||
|
// then you should check https://github.com/iris-contrib/middleware/tree/master/cors
|
||||||
|
|
||||||
|
v1 := app.Party("/api/v1")
|
||||||
|
{
|
||||||
|
v1.Post("/home", func(c *iris.Context) {
|
||||||
|
app.Log(iris.DevMode, "lalala")
|
||||||
|
c.WriteString("Hello from /home")
|
||||||
|
})
|
||||||
|
v1.Get("/g", func(c *iris.Context) {
|
||||||
|
app.Log(iris.DevMode, "lalala")
|
||||||
|
c.WriteString("Hello from /home")
|
||||||
|
})
|
||||||
|
v1.Post("/h", func(c *iris.Context) {
|
||||||
|
app.Log(iris.DevMode, "lalala")
|
||||||
|
c.WriteString("Hello from /home")
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
app.Listen(":8080")
|
||||||
|
}
|
|
@ -4,7 +4,7 @@ package cors
|
||||||
// | Cors wrapper usage |
|
// | Cors wrapper usage |
|
||||||
// +------------------------------------------------------------+
|
// +------------------------------------------------------------+
|
||||||
//
|
//
|
||||||
// import "github.com/kataras/iris/adaptors/cors"
|
// import "gopkg.in/kataras/iris.v6/adaptors/cors"
|
||||||
//
|
//
|
||||||
// app := iris.New()
|
// app := iris.New()
|
||||||
// app.Adapt(cors.New(cors.Options{})))
|
// app.Adapt(cors.New(cors.Options{})))
|
||||||
|
|
Loading…
Reference in New Issue
Block a user