Commit 96060f71 by mushishixian

添加中间件

parent 18fabaf1
Showing with 20 additions and 1 deletions
package middleware
import (
"github.com/gin-contrib/cors"
"github.com/gin-gonic/gin"
"search_server/pkg/config"
"time"
)
func Cors() gin.HandlerFunc {
corsDomain := config.Get("web.cors_domain").Strings(",")
return cors.New(cors.Config{
AllowOrigins: corsDomain,
AllowMethods: []string{"POST", "GET", "PUT", "DELETE"},
AllowCredentials: true,
MaxAge: 12 * time.Hour,
})
}
......@@ -3,6 +3,7 @@ package routes
import (
"github.com/gin-gonic/gin"
"search_server/controller"
"search_server/middleware"
)
//初始化路由
......@@ -10,7 +11,7 @@ func InitRouter() *gin.Engine {
r := gin.New()
r.Use(gin.Logger())
r.Use(gin.Recovery())
r.Use(middleware.Cors())
//路由
r.POST("/search/bom/autospu", controller.AutoSpu)
r.POST("/search/bom/recommend", controller.Recommend)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment