Skip to content

Commit

Permalink
Support the JSONP
Browse files Browse the repository at this point in the history
  • Loading branch information
shibingli committed Apr 11, 2017
1 parent 79426c0 commit 94df552
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 25 deletions.
18 changes: 13 additions & 5 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,32 @@

开源捐献日志(感谢各位网友的支持)

2017.03.16
2017.04.05

@Jager`(qq:287988783) 捐献:50.00 元(人民币)
@朱小四(weichat:juechengke) 捐献:200.00 元(人民币)

2017.02.25

@jerry2049 捐献:100.00 元(人民币)
@jerry2049 捐献:100.00 元(人民币)

2016.03.13

@非非不在家(qq:762810120) 捐献:8.88 元(人民币)
@非非不在家(qq:762810120) 捐献:8.88 元(人民币)

2016.05.16

@玩蝴蝶的法师(qq:43588476) 捐献:50.00 元(人民币)
@玩蝴蝶的法师(qq:43588476) 捐献:50.00 元(人民币)

更新日志

2017.04.11

更新:
1、添加对 JSONP 的支持,解决 JQuery 跨域请求的需求。
2、配置文件新增 JSONP 的支持。

感谢 @朱小四(weichat:juechengke) 提出需求。

2017.03.27

修证:
Expand Down
4 changes: 3 additions & 1 deletion conf/conf.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,11 @@
"template_dir": "template/default",
"template_suffix": ".html",
"session_timeout": 1800,
"enable_jsonp": false,
"jsonp_param": "callback",
"enable_gzip": true,
"enable_tls": false,
"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,webconsole.daoapp.io,webconsole.realclouds.org,webconsole.realclouds.org:8080,ksc-03.realclouds.org:8080,ksc-03.realclouds.org,webconsole.realclouds.org:8443",
"cors_white_list": "127.0.0.1,127.0.0.1:8081,127.0.0.1:8443,localhost,localhost:8081,localhost:8443,pangu.cloud,www.pangu.cloud,webconsole.daoapp.io,webconsole.realclouds.org,webconsole.realclouds.org:8080,ksc-03.realclouds.org:8080,ksc-03.realclouds.org,webconsole.realclouds.org:8443,b.com:8081,a.com:8081",
"enable_fcgi": false,
"tls_cert": "214044428560678.pem",
"tls_key": "214044428560678.key",
Expand Down
16 changes: 0 additions & 16 deletions src/apibox.club/test/test.go

This file was deleted.

2 changes: 2 additions & 0 deletions src/apibox.club/utils/common.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,8 @@ type (
StaticDir string `json:"static_dir" xml:"static_dir"`
TemplateDir string `json:"template_dir" xml:"template_dir"`
TemplateSuffix string `json:"template_suffix" xml:"template_suffix"`
EnableJSONP bool `json:"enable_jsonp" xml:"enable_jsonp"`
JSONPParam string `json:"jsonp_param" xml:"jsonp_param"`
EnableTLS bool `json:"enable_tls" xml:"enable_tls"`
CorsWhiteList string `json:"cors_white_list" xml:"cors_white_list"`
EnableFcgi bool `json:"enable_fcgi" xml:"enable_fcgi"`
Expand Down
14 changes: 11 additions & 3 deletions src/apibox.club/website/init.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package website

import (
"apibox.club/server"
"apibox.club/utils"
"bytes"
"encoding/json"
"encoding/xml"
Expand All @@ -12,6 +10,9 @@ import (
"path/filepath"
"strings"
"text/template"

"apibox.club/server"
"apibox.club/utils"
)

var (
Expand Down Expand Up @@ -149,7 +150,14 @@ func (c *Context) OutJson(obj interface{}) {
if nil != err {
http.Error(c.w, err.Error(), http.StatusInternalServerError)
} else {
apibox.Gzip_Binary(b, c.w, c.r)
if Conf.Web.EnableJSONP {
jsonpParam := c.GetFormValue(Conf.Web.JSONPParam)
ret := jsonpParam + "(" + string(b) + ")"
apibox.Log_Debug("JSONP:", ret)
apibox.Gzip_Binary([]byte(ret), c.w, c.r)
} else {
apibox.Gzip_Binary(b, c.w, c.r)
}
}
return
}
Expand Down

0 comments on commit 94df552

Please sign in to comment.