fix bug
This commit is contained in:
@@ -2,26 +2,32 @@
|
|||||||
package middleware
|
package middleware
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"net/http"
|
"time"
|
||||||
|
|
||||||
|
"github.com/gin-contrib/cors"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
const (
|
|
||||||
allowedHeaders = "Origin, Content-Length, Content-Type, Workspace, Request-Id, Authorization, Token"
|
|
||||||
allowedMethods = "GET, POST, PUT, PATCH, DELETE, HEAD, OPTIONS"
|
|
||||||
)
|
|
||||||
|
|
||||||
// Cors 允许平台前端跨域调用 API,包括状态更新使用的 PATCH 方法。
|
// Cors 允许平台前端跨域调用 API,包括状态更新使用的 PATCH 方法。
|
||||||
func Cors() gin.HandlerFunc {
|
func Cors() gin.HandlerFunc {
|
||||||
return func(ctx *gin.Context) {
|
return cors.New(cors.Config{
|
||||||
ctx.Header("Access-Control-Allow-Origin", "*")
|
AllowOriginFunc: func(origin string) bool {
|
||||||
ctx.Header("Access-Control-Allow-Headers", allowedHeaders)
|
return true // 允许所有域名
|
||||||
ctx.Header("Access-Control-Allow-Methods", allowedMethods)
|
},
|
||||||
if ctx.Request.Method == http.MethodOptions {
|
AllowMethods: []string{"GET", "POST", "PUT", "PATCH", "DELETE", "OPTIONS"},
|
||||||
ctx.AbortWithStatus(http.StatusNoContent)
|
AllowHeaders: []string{
|
||||||
return
|
"Origin",
|
||||||
}
|
"Content-Type",
|
||||||
ctx.Next()
|
"Authorization",
|
||||||
}
|
"X-Requested-With",
|
||||||
|
"X-App-Id",
|
||||||
|
"X-Doip-App-Id",
|
||||||
|
"X-Lowcode-Mode",
|
||||||
|
"X-Lowcode-Org",
|
||||||
|
"Token",
|
||||||
|
},
|
||||||
|
ExposeHeaders: []string{"Content-Length"},
|
||||||
|
AllowCredentials: true, // 支持 credentials
|
||||||
|
MaxAge: 12 * time.Hour,
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ http://rest.heqiapp.com {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
heqiapp.com {
|
http://heqiapp.com {
|
||||||
encode gzip
|
encode gzip
|
||||||
root * /data/heqiapp/dist/site
|
root * /data/heqiapp/dist/site
|
||||||
|
|
||||||
@@ -26,7 +26,7 @@ heqiapp.com {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
www.heqiapp.com {
|
http://www.heqiapp.com {
|
||||||
encode gzip
|
encode gzip
|
||||||
root * /data/heqiapp/dist/site
|
root * /data/heqiapp/dist/site
|
||||||
|
|
||||||
@@ -44,7 +44,7 @@ www.heqiapp.com {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
p.heqiapp.com {
|
http://p.heqiapp.com {
|
||||||
encode gzip
|
encode gzip
|
||||||
root * /data/heqiapp/dist/platform
|
root * /data/heqiapp/dist/platform
|
||||||
|
|
||||||
@@ -61,7 +61,7 @@ p.heqiapp.com {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
z.heqiapp.com {
|
http://z.heqiapp.com {
|
||||||
encode gzip
|
encode gzip
|
||||||
root * /data/heqiapp/dist/gas
|
root * /data/heqiapp/dist/gas
|
||||||
|
|
||||||
@@ -78,7 +78,7 @@ z.heqiapp.com {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
d.heqiapp.com {
|
http://d.heqiapp.com {
|
||||||
encode gzip
|
encode gzip
|
||||||
root * /data/heqiapp/dist/delivery
|
root * /data/heqiapp/dist/delivery
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user