mirror of
https://github.com/cowardmrx/gin_cors.git
synced 2026-08-13 14:19:20 +08:00
:tada:gin的cors跨域中间件
This commit is contained in:
29
cors_test.go
Normal file
29
cors_test.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package gin_cors
|
||||
|
||||
import (
|
||||
"github.com/gin-gonic/gin"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestCors_CorsMiddleware(t *testing.T) {
|
||||
|
||||
r := gin.Default()
|
||||
|
||||
cors := &Cors{
|
||||
AccessControlAllowOrigins: []string{
|
||||
"http://localhost",
|
||||
},
|
||||
AccessControlAllowMethods: "PUT,POST,GET,DELETE",
|
||||
}
|
||||
|
||||
r.Use(cors.CorsMiddleware())
|
||||
|
||||
r.POST("/te", func(c *gin.Context) {
|
||||
c.JSON(200, gin.H{
|
||||
"data": "this is data",
|
||||
})
|
||||
})
|
||||
|
||||
r.Run(":7878")
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user