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
96060f71
authored
Jul 02, 2020
by
mushishixian
Browse files
Options
_('Browse Files')
Download
Email Patches
Plain Diff
添加中间件
parent
18fabaf1
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
1 deletions
middleware/cors.go
routes/router.go
middleware/cors.go
0 → 100644
View file @
96060f71
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
,
})
}
routes/router.go
View file @
96060f71
...
@@ -3,6 +3,7 @@ package routes
...
@@ -3,6 +3,7 @@ package routes
import
(
import
(
"github.com/gin-gonic/gin"
"github.com/gin-gonic/gin"
"search_server/controller"
"search_server/controller"
"search_server/middleware"
)
)
//初始化路由
//初始化路由
...
@@ -10,7 +11,7 @@ func InitRouter() *gin.Engine {
...
@@ -10,7 +11,7 @@ func InitRouter() *gin.Engine {
r
:=
gin
.
New
()
r
:=
gin
.
New
()
r
.
Use
(
gin
.
Logger
())
r
.
Use
(
gin
.
Logger
())
r
.
Use
(
gin
.
Recovery
())
r
.
Use
(
gin
.
Recovery
())
r
.
Use
(
middleware
.
Cors
())
//路由
//路由
r
.
POST
(
"/search/bom/autospu"
,
controller
.
AutoSpu
)
r
.
POST
(
"/search/bom/autospu"
,
controller
.
AutoSpu
)
r
.
POST
(
"/search/bom/recommend"
,
controller
.
Recommend
)
r
.
POST
(
"/search/bom/recommend"
,
controller
.
Recommend
)
...
...
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