跨域

parent 741596fa
Showing with 10 additions and 8 deletions
...@@ -17,6 +17,8 @@ func Cors() gin.HandlerFunc { ...@@ -17,6 +17,8 @@ func Cors() gin.HandlerFunc {
corsDomain = append(corsDomain, "http://ichunt.com") corsDomain = append(corsDomain, "http://ichunt.com")
corsDomain = append(corsDomain, "https://t.ichunt.com") corsDomain = append(corsDomain, "https://t.ichunt.com")
corsDomain = append(corsDomain, "http://t.ichunt.com") corsDomain = append(corsDomain, "http://t.ichunt.com")
corsDomain = append(corsDomain, "http://a.liexin.com")
corsDomain = append(corsDomain, "http://www.liexin.com")
return cors.New(cors.Config{ return cors.New(cors.Config{
AllowOrigins: corsDomain, AllowOrigins: corsDomain,
AllowHeaders: []string{"x-requested-with", "Authorization", "Content-Type"}, AllowHeaders: []string{"x-requested-with", "Authorization", "Content-Type"},
......
...@@ -6,7 +6,6 @@ import ( ...@@ -6,7 +6,6 @@ import (
"runtime" "runtime"
"search_server/pkg/logger" "search_server/pkg/logger"
"strconv" "strconv"
"strings"
) )
type Response struct { type Response struct {
...@@ -61,13 +60,14 @@ func Output(ctx *gin.Context, errCode int, errMsg string, data interface{}) { ...@@ -61,13 +60,14 @@ func Output(ctx *gin.Context, errCode int, errMsg string, data interface{}) {
if ctx.DefaultQuery("callback", "") != "" { if ctx.DefaultQuery("callback", "") != "" {
ctx.JSONP(200, response) ctx.JSONP(200, response)
} else { } else {
referer := ctx.Request.Referer() //println("nnni")
referer = strings.TrimRight(referer, "/") //referer := ctx.Request.Referer()
ctx.Header("Access-Control-Allow-Origin", referer) //referer = strings.TrimRight(referer, "/")
ctx.Header("Access-Control-Allow-Credentials", "true") //ctx.Header("Access-Control-Allow-Origin", "http://a.liexin.com")
ctx.Header("Access-Control-Allow-Headers", "*") //ctx.Header("Access-Control-Allow-Credentials", "true")
ctx.Header("Access-Control-Allow-Methods", "GET,HEAD,POST,PUT,DELETE,OPTIONS") //ctx.Header("Access-Control-Allow-Headers", "*")
ctx.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type") //ctx.Header("Access-Control-Allow-Methods", "GET,HEAD,POST,PUT,DELETE,OPTIONS")
//ctx.Header("Access-Control-Expose-Headers", "Content-Length, Access-Control-Allow-Origin, Access-Control-Allow-Headers, Content-Type")
//允许跨站访问的站点域名 //允许跨站访问的站点域名
//跨域请求头设置 //跨域请求头设置
ctx.JSON(200, response) ctx.JSON(200, response)
......
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