目录
semantic-release-bot

Release 3.0.0

[skip ci]

3.0.0 (2025-01-11)

⚠ BREAKING CHANGES

  • drop Node.js < 18.19.0 support

part of https://github.com/eggjs/egg/issues/3644

https://github.com/eggjs/egg/issues/5257

Summary by CodeRabbit

Release Notes

  • New Features

    • Added TypeScript support for the JSONP plugin
    • Modernized project structure with ES module syntax
    • Enhanced type definitions and configuration
    • Introduced new GitHub Actions workflows for CI/CD
    • Added a new class for JSONP error handling
  • Breaking Changes

    • Renamed package from egg-jsonp to @eggjs/jsonp
    • Dropped support for Node.js versions below 18.19.0
    • Refactored configuration and middleware approach
  • Improvements

    • Updated GitHub Actions workflows for CI/CD
    • Improved security checks for JSONP requests
    • Added more robust error handling
    • Enhanced logging configuration
  • Dependency Updates

    • Updated core dependencies
    • Migrated to modern TypeScript tooling

Features

  • support cjs and esm both by tshy (#12) (9136768)
1年前23次提交

@eggjs/jsonp

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

An egg plugin for jsonp support.

Requirements

  • egg >= 4.x

Install

npm i @eggjs/jsonp

Usage

// {app_root}/config/plugin.ts

export default {
  jsonp: {
    enable: true,
    package: '@eggjs/jsonp',
  },
};

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

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');

Questions & Suggestions

Please open an issue here.

License

MIT

Contributors

Contributors

Made with contributors-img.

关于
95.0 KB
邀请码
    Gitlink(确实开源)
  • 加入我们
  • 官网邮箱:gitlink@ccf.org.cn
  • QQ群
  • QQ群
  • 公众号
  • 公众号

版权所有:中国计算机学会技术支持:开源发展技术委员会
京ICP备13000930号-9 京公网安备 11010802032778号