You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
22 lines
621 B
22 lines
621 B
2 years ago
|
package middlewares
|
||
|
|
||
|
import (
|
||
|
"net/http"
|
||
|
|
||
|
"github.com/gin-gonic/gin"
|
||
|
)
|
||
|
|
||
|
func Axios() gin.HandlerFunc {
|
||
|
return func(c *gin.Context) {
|
||
|
c.Writer.Header().Set("Access-Control-Allow-Origin", "*") //域名*代表所有的都可以访问
|
||
|
c.Writer.Header().Set("Access-Control-Max-Age", "86400") //缓存时间
|
||
|
c.Writer.Header().Set("Access-Control-Allow-Methods", "*") //访问的方法GET,POST
|
||
|
c.Writer.Header().Set("Access-Control-Allow-Headers", "*")
|
||
|
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
|
||
|
if c.Request.Method == http.MethodOptions {
|
||
|
c.AbortWithStatus(200)
|
||
|
}
|
||
|
c.Next()
|
||
|
}
|
||
|
}
|