Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
D
demo-go
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
彭芳
demo-go
Commits
5d0f254f
Commit
5d0f254f
authored
Feb 23, 2023
by
彭芳
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
minor: add cors
parent
e1b7b845
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
8 additions
and
1 deletion
+8
-1
common.go
internal/router/mid/common.go
+7
-0
web.go
internal/router/web.go
+1
-1
No files found.
internal/router/mid/common.go
View file @
5d0f254f
...
...
@@ -28,3 +28,10 @@ func (p *Common) PassMethods(c *gin.Context) {
return
}
}
// Cors 允许服务器跨域访问
func
(
p
*
Common
)
Cors
(
c
*
gin
.
Context
)
{
c
.
Header
(
"Access-Control-Allow-Origin"
,
"*"
)
c
.
Header
(
"Access-Control-Allow-Methods"
,
"OPTIONS,HEAD,GET,POST,DELETE,PUT,PATCH"
)
c
.
Header
(
"Access-Control-Allow-Headers"
,
"Authorization,Content-Type,Content-Range,Content-Disposition,token,access-token,device,x-requested-with"
)
}
internal/router/web.go
View file @
5d0f254f
...
...
@@ -31,7 +31,7 @@ type Web struct {
// @in header
// @name token
func
(
p
*
Web
)
RouterInit
(
engine
*
gin
.
Engine
)
{
engine
.
Use
(
p
.
Common
.
SetRequestId
,
p
.
Common
.
PassMethods
)
engine
.
Use
(
p
.
Common
.
SetRequestId
,
p
.
Common
.
Cors
,
p
.
Common
.
PassMethods
)
engine
.
NoRoute
(
func
(
c
*
gin
.
Context
)
{
c
.
JSON
(
http
.
StatusNotFound
,
gin
.
H
{
"code"
:
"404"
,
"message"
:
"Page not found"
})
})
...
...
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