eggjs/egg-jsonp

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

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

egg-jsonp

NPM version build status Test coverage David deps Known Vulnerabilities npm download

An egg plugin for jsonp support.

Install
m i egg-jsonp --save
Usage
app_root}/config/plugin.js
rts.jsonp = {
able: true,
ckage: 'egg-jsonp',

Configuration

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.

API
Example

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');
Questions & Suggestions

Please open an issue here.

License

MIT


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.