Name: egg-jsonp
Owner: egg
Description: jsonp support for egg, with security check inside
Created: 2017-01-22 08:04:08.0
Updated: 2018-05-08 15:03:18.0
Pushed: 2017-11-11 00:44:11.0
Homepage: null
Size: 24
Language: JavaScript
GitHub Committers
User | Most Recent Commit | # Commits |
---|
Other Committers
User | Most Recent Commit | # Commits |
---|
An egg plugin for jsonp support.
m i egg-jsonp --save
app_root}/config/plugin.js
rts.jsonp = {
able: true,
ckage: 'egg-jsonp',
[ '_callback', 'callback' ]
50
if whiteList's type is RegExp
, referrer must match whiteList
, pay attention to the first ^
and last /
.
rts.jsonp = {
iteList: /^https?:\/\/test.com\//,
atchs referrer:
ttps://test.com/hello
ttp://test.com/
if whiteList's type is String
and starts with .
:
rts.jsonp = {
iteList: '.test.com',
atchs domain test.com:
ttps://test.com/hello
ttp://test.com/
atchs subdomain
ttps://sub.test.com/hello
ttp://sub.sub.test.com/
if whiteList's type is String
and not starts with .
:
rts.jsonp = {
iteList: 'sub.test.com',
nly matchs domain sub.test.com:
ttps://sub.test.com/hello
ttp://sub.test.com/
whiteList also can be an array:
rts.jsonp = {
iteList: [ '.foo.com', '.bar.com' ],
see config/config.default.js for more detail.
In app/router.js
reate once and use in any router you want to support jsonp.
t jsonp = app.jsonp();
get('/default', jsonp, 'jsonp.index');
get('/another', jsonp, 'jsonp.another');
ustomize by create another jsonp middleware with specific sonfigurations.
get('/customize', app.jsonp({ callback: 'fn' }), 'jsonp.customize');
Please open an issue here.