egg-cors
cors plugin for egg
Last updated 3 years ago by fengmk2 .
Repository · Bugs · Original npm · Tarball · package.json
$ npm install egg-cors 
SYNC missed versions from official npm registry.

egg-cors

NPM version Node.js CI Test coverage npm download

CORS plugin for egg, based on @koa/cors.

Install

$ npm i egg-cors --save

Usage

// {app_root}/config/plugin.js
exports.cors = {
  enable: true,
  package: 'egg-cors',
};

egg-cors works internally with egg-security. By defining the property of domainWhiteList on object security, you have successfully informed the framework to whitelist the passed domains.

When you make a request from client side, egg should return an Access-Control-Allow-Origin response header with the domain that you passed in along with the payload and status code 200.

exports.security = {
  domainWhiteList: [ 'http://localhost:4200' ],
};

Configuration

Support all configurations in @koa/cors.

// {app_root}/config/config.default.js
exports.cors = {
  // {string|Function} origin: '*',
  // {string|Array} allowMethods: 'GET,HEAD,PUT,POST,DELETE,PATCH'
};

If the origin is set, the plugin will follow it to set the Access-Control-Allow-Origin and ignore the security.domainWhiteList. Otherwise, the security.domainWhiteList which is default will take effect as described above.

Security

Only in safe domain list support CORS when security plugin enabled.

Questions & Suggestions

Please open an issue here.

License

MIT

Contributors


atian25


dead-horse


fengmk2


brickyang


sinchang


XadillaX


mattma


SoraYama


Yelmor


angela-1


waitingsong

This project follows the git-contributor spec, auto updated at Mon Dec 11 2023 13:25:00 GMT+0800.

Current Tags

  • 3.0.1                                ...           latest (3 years ago)
  • 2.2.4                                ...           latest-2 (3 years ago)

16 Versions

  • 3.0.1                                ...           3 years ago
  • 2.2.4                                ...           3 years ago
  • 3.0.0                                ...           3 years ago
  • 2.2.3                                ...           7 years ago
  • 2.2.2                                ...           7 years ago
  • 2.2.1                                ...           7 years ago
  • 2.2.0                                ...           8 years ago
  • 2.1.2                                ...           8 years ago
  • 2.1.1                                ...           8 years ago
  • 2.1.0                                ...           8 years ago
  • 2.0.0                                ...           9 years ago
  • 1.2.0                                ...           9 years ago
  • 1.1.0                                ...           10 years ago
  • 1.0.0                                ...           10 years ago
  • 0.0.2                                ...           10 years ago
  • 0.0.1                                ...           11 years ago
Downloads
Total 33
Today 0
This Week 0
This Month 17
Last Day 0
Last Week 1
Last Month 0
Dependencies (1)
Dev Dependencies (7)
Dependents (1)

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