@eggjs/jsonp
jsonp support for egg
Last updated 2 months ago by GitHub Actions .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ npm install @eggjs/jsonp 
SYNC missed versions from official npm registry.

@eggjs/jsonp

NPM version Known Vulnerabilities npm download Node.js Version PRs Welcome

An egg plugin for jsonp support.

Usage

egg built-in plugin jsonp is enabled by default.

// {app_root}/config/plugin.ts

export default {
  jsonp: {
    enable: true,
  },
};

Configuration

  • {String|Array} callback - jsonp callback method key, default to [ '_callback', 'callback' ]
  • {Number} limit - callback method name's max length, default to 50
  • {Boolean} csrf - enable csrf check or not. default to false
  • {String|RegExp|Array} whiteList - referrer white list

if whiteList's type is RegExp, referrer must match whiteList, pay attention to the first ^ and last /.

export default {
  jsonp: {
    whiteList: /^https?:\/\/test.com\//,
  },
};

// matchs referrer:
// https://test.com/hello
// http://test.com/

if whiteList's type is String and starts with .:

export default {
  jsonp: {
    whiteList: '.test.com',
  },
};

// matchs domain test.com:
// https://test.com/hello
// http://test.com/

// matchs subdomain
// https://sub.test.com/hello
// http://sub.sub.test.com/

if whiteList's type is String and not starts with .:

export default {
  jsonp: {
    whiteList: 'sub.test.com',
  },
};

// only matchs domain sub.test.com:
// https://sub.test.com/hello
// http://sub.test.com/

whiteList also can be an array:

export default {
  jsonp: {
    whiteList: ['.foo.com', '.bar.com'],
  },
};

see config/config.default.ts for more detail.

API

  • ctx.acceptJSONP - detect if response should be jsonp, readonly

Example

Standard Application Usage

In app/router.ts

// Create once and use in any router you want to support jsonp.
const jsonp = app.jsonp();

app.get('/default', jsonp, 'jsonp.index');
app.get('/another', jsonp, 'jsonp.another');

// Customize by create another jsonp middleware with specific configurations.
app.get('/customize', app.jsonp({ callback: 'fn' }), 'jsonp.customize');

tegg HttpController Usage

TODO: TBD

Questions & Suggestions

Please open an issue here.

License

MIT

Contributors

Contributors

Made with contributors-img.

Current Tags

  • 4.0.2-beta.27                                ...           beta (2 months ago)
  • 4.1.0                                ...           latest (2 months ago)
  • 4.0.2-rc.1                                ...           rc (2 months ago)

53 Versions

  • 4.1.0                                ...           2 months ago
  • 4.0.2                                ...           2 months ago
  • 4.0.2-rc.1                                ...           2 months ago
  • 4.0.2-rc.0                                ...           2 months ago
  • 4.0.2-beta.27                                ...           2 months ago
  • 4.0.2-beta.26                                ...           4 months ago
  • 4.0.2-beta.25                                ...           4 months ago
  • 4.0.2-beta.24                                ...           4 months ago
  • 4.0.2-beta.23                                ...           5 months ago
  • 4.0.2-beta.22                                ...           5 months ago
  • 4.0.2-beta.20                                ...           5 months ago
  • 4.0.2-beta.19                                ...           5 months ago
  • 4.0.2-beta.17                                ...           5 months ago
  • 4.0.2-beta.16                                ...           5 months ago
  • 4.0.2-beta.15                                ...           5 months ago
  • 4.0.2-beta.14                                ...           5 months ago
  • 4.0.2-beta.13                                ...           5 months ago
  • 4.0.2-beta.12                                ...           5 months ago
  • 4.0.2-beta.11                                ...           5 months ago
  • 4.0.2-beta.10                                ...           5 months ago
  • 4.0.2-beta.9                                ...           8 months ago
  • 4.0.2-beta.8                                ...           8 months ago
  • 4.0.2-beta.7                                ...           8 months ago
  • 4.0.2-beta.6                                ...           8 months ago
  • 4.0.2-beta.5                                ...           8 months ago
  • 4.0.2-beta.4                                ...           8 months ago
  • 4.0.2-beta.3                                ...           9 months ago
  • 4.0.2-beta.2                                ...           9 months ago
  • 4.0.2-beta.1                                ...           9 months ago
  • 4.0.2-beta.0                                ...           9 months ago
  • 4.0.1-beta.0                                ...           9 months ago
  • 4.0.0-beta.36                                ...           a year ago
  • 4.0.0-beta.35                                ...           a year ago
  • 4.0.0-beta.34                                ...           a year ago
  • 4.0.0-beta.33                                ...           a year ago
  • 4.0.0-beta.32                                ...           a year ago
  • 4.0.0-beta.31                                ...           a year ago
  • 4.0.0-beta.30                                ...           a year ago
  • 4.0.0-beta.29                                ...           a year ago
  • 4.0.0-beta.28                                ...           a year ago
  • 4.0.0-beta.27                                ...           a year ago
  • 4.0.0-beta.26                                ...           a year ago
  • 4.0.0-beta.25                                ...           a year ago
  • 4.0.0-beta.24                                ...           a year ago
  • 4.0.0-beta.23                                ...           a year ago
  • 4.0.0-beta.22                                ...           a year ago
  • 4.0.0-beta.21                                ...           a year ago
  • 4.0.0-beta.20                                ...           a year ago
  • 4.0.0-beta.19                                ...           a year ago
  • 4.0.0-beta.18                                ...           a year ago
  • 4.0.0-beta.17                                ...           a year ago
  • 4.0.0-beta.15                                ...           a year ago
  • 3.0.0                                ...           2 years ago
Downloads
Total 195
Today 0
This Week 1
This Month 143
Last Day 0
Last Week 137
Last Month 52
Dependencies (1)
Dev Dependencies (4)
Dependents (1)

© 2010 - cnpmjs.org x YWFE | Home | YWFE