Skip to content

Commit

Permalink
1.3
Browse files Browse the repository at this point in the history
新增:
        添加跨域白名单的支持。(conf/conf.json.
cors_white_list:"127.0.0.1,www.xxx.com");
  • Loading branch information
shibingli committed May 17, 2016
1 parent 64c7d20 commit 2751a9c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
3 changes: 1 addition & 2 deletions conf/conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,7 @@
"session_timeout": 1800,
"enable_gzip": true,
"enable_tls": false,
"enable_cors":false,
"cors_white_list":"127.0.0.1,127.0.0.1:8080,127.0.0.1:8443,localhost,localhost:8080,localhost:8443",
"cors_white_list":"127.0.0.1,127.0.0.1:8080,127.0.0.1:8443,localhost,localhost:8080,localhost:8443,pangu.cloud,www.pangu.cloud",
"enable_fcgi": false,
"tls_cert": "ssl_cert.crt",
"tls_key": "ssl_cert.key",
Expand Down
14 changes: 5 additions & 9 deletions src/apibox.club/website/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,16 +87,12 @@ var upgrader = websocket.Upgrader{
ReadBufferSize: 1024,
WriteBufferSize: 1024,
CheckOrigin: func(r *http.Request) bool {

// 跨域处理,这里需要做一下安全防护。比如:请求白名单(这里只是简单的做了请求HOST白名单)
cors := Conf.Web.EnableCORS
if cors {
cwl := Conf.Web.CorsWhiteList
apibox.Log_Debug("Cors white list:", cwl)
for _, v := range strings.Split(cwl, ",") {
if strings.EqualFold(strings.TrimSpace(v), r.Host) {
return true
}
cwl := Conf.Web.CorsWhiteList
apibox.Log_Debug("Cors white list:", cwl)
for _, v := range strings.Split(cwl, ",") {
if strings.EqualFold(strings.TrimSpace(v), r.Host) {
return true
}
}
return false
Expand Down

0 comments on commit 2751a9c

Please sign in to comment.