Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
杨树贤
/
search_server
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Settings
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
658ba30e
authored
Feb 02, 2023
by
SUDPTDUBLXEROFX\Administrator
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
跨域
parent
741596fa
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
8 deletions
middleware/cors.go
pkg/common/response.go
middleware/cors.go
View file @
658ba30e
...
@@ -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"
},
...
...
pkg/common/response.go
View file @
658ba30e
...
@@ -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
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment