Skip to content

Commit

Permalink
fix CORS
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangbiao committed Mar 31, 2020
1 parent 8131ff2 commit 184e995
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
3 changes: 3 additions & 0 deletions ChangeLog.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
Change Log 更新说明
------------------------------
## 2020-03-31 v1.1.4
1. 解决前后端分离跨域部署认证问题

## 2020-03-31 v1.1.3
1. gf升级到最新版本V1.12.1,gtoken升级到v1.3.15

Expand Down
22 changes: 13 additions & 9 deletions router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,24 +25,27 @@ import (
func bindRouter() {
urlPath := g.Config().GetString("url-path")
s := g.Server()

// 中间件
// 允许跨域
s.BindMiddleware("/*", func(r *ghttp.Request) {
r.Response.CORSDefault()
r.Middleware.Next()
})
// 日志拦截
s.BindMiddleware(urlPath+"/*", middle.MiddlewareLog)
// 通用属性
s.BindMiddleware(urlPath+"/*", middle.MiddlewareCommon)

// 首页
s.BindHandler(urlPath+"/", common.Login)
s.BindHandler(urlPath+"/main.html", common.Index)
s.BindHandler(urlPath+"/login", common.Login)

s.BindHandler(urlPath+"/welcome", common.Welcome)
s.BindHandler(urlPath+"/admin/welcome.html", common.Welcome)
// 中间件
s.BindMiddleware(urlPath+"/*", middle.MiddlewareLog)
s.BindMiddleware(urlPath+"/*", middle.MiddlewareCommon)

s.Group(urlPath+"/system", func(g *ghttp.RouterGroup) {
// 允许跨域
g.Middleware(func(r *ghttp.Request) {
r.Response.CORSDefault()
r.Middleware.Next()
})

// 系统路由
userAction := new(user.Action)
g.ALL("user", userAction)
Expand Down Expand Up @@ -86,6 +89,7 @@ func bindRouter() {
LogoutPath: "/user/logout",
LogoutBeforeFunc: common.LogoutBefore,
AuthPaths: g.SliceStr{"/user", "/system"},
GlobalMiddleware: true,
AuthBeforeFunc: func(r *ghttp.Request) bool {
// 静态页面不拦截
if r.IsFileRequest() {
Expand Down

0 comments on commit 184e995

Please sign in to comment.