Skip to content

Commit

Permalink
Merge pull request #155 from trheyi/main
Browse files Browse the repository at this point in the history
[Add] Custom CORS Headers
  • Loading branch information
trheyi authored Oct 4, 2023
2 parents 6a372a0 + bf8dff3 commit e020726
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
8 changes: 4 additions & 4 deletions api/http.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,8 +167,8 @@ func (http HTTP) Route(router gin.IRoutes, path Path, allows ...string) {
// fmt.Println("referer is:", referer)
c.Writer.Header().Set("Access-Control-Allow-Origin", origin)
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
c.Writer.Header().Set("Access-Control-Allow-Headers", allowHeaders)
c.Writer.Header().Set("Access-Control-Allow-Methods", allowMethods)
}
})
}
Expand Down Expand Up @@ -229,8 +229,8 @@ func (http HTTP) setCorsOption(path string, allows map[string]bool, router gin.I
referer = fmt.Sprintf("%s://%s", url.Scheme, url.Host)
c.Writer.Header().Set("Access-Control-Allow-Origin", referer)
c.Writer.Header().Set("Access-Control-Allow-Credentials", "true")
c.Writer.Header().Set("Access-Control-Allow-Headers", "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With")
c.Writer.Header().Set("Access-Control-Allow-Methods", "POST, OPTIONS, GET, PUT")
c.Writer.Header().Set("Access-Control-Allow-Headers", allowHeaders)
c.Writer.Header().Set("Access-Control-Allow-Methods", allowMethods)
c.AbortWithStatus(204)
}
})
Expand Down
3 changes: 3 additions & 0 deletions api/types.go
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package api

const allowHeaders = "Content-Type, Content-Length, Accept-Encoding, X-CSRF-Token, Authorization, accept, origin, Cache-Control, X-Requested-With, Yao-Gateway-Billing, Yao-Request-Uid, Yao-Builder-Uid"
const allowMethods = "POST, GET, OPTIONS, PUT, DELETE, HEAD, PATCH"

// API 数据接口
type API struct {
ID string `jsong:"id"`
Expand Down

0 comments on commit e020726

Please sign in to comment.