3.0.1 • Published 1 year ago

egg-cors v3.0.1

Weekly downloads
9,960
License
-
Repository
github
Last release
1 year ago

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

atian25dead-horsefengmk2brickyangsinchangXadillaX
mattmaSoraYamaYelmorangela-1waitingsong

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

iwiiegg-poppy-api-frameworkdingeggjia-sleepsparrow-bird-serverumo-bakeryegg-framework-thsbase@infinitebrahmanuniverse/nolb-egg-c@everything-registry/sub-chunk-1557furjiko-egg-frameworkwired-eggwenshuai-serverxc.basesparrow-servervue-egg-serviceves@cocacms/cocacmsjoyu-egg-frameworkiris-eggkejujv-accountstudy-gaiajs-adminumo-mockuss_abcdefg_lileituia-egg-update@chandre/egg-frameworkxy-basezzestemplate@easy-team/res@graphi/api@fzo/fzo-server@jianghujs/jianghu@jeff-tian/alpha@i-orz/egg-framework@kecoyo/egg-framework@push.fun/layer@poppies/egg-poppy-api-framework@nostar/egg-ns-framework@pipcook/daemonminerva-api-frameworkrojer-eggjsnode-coreres-react-asset-boilerplateqiaokun-eggqhkj-frameworksmart-easyteam-egg-react-spa-boilerplatehtticeworks-serverhtmlcoininfo-apiheronode-nodeheornode-nodellb-clilmq-egg-backendld-egg-frame@ubancloud/core@ubancloud/core-lite@tuia/tuia-egg@yanyufanchen/vue-wpui@yydsorz/egg-framework@zhaofeng-shu33/iceworks-server@taotieh/back_giscomcb-eggcnpmcorecreate-apihubcore-server_deepbw-bff-frameworkbw-bff-framework-plusdisject-serverdineggeasy-element-admindxs-midwayegg-lt-frameworkegg-lt-framework-adminegg-mongoose-curdegg-moeegg-mongo-frameworkeasy-react-adminegg-originegg-poppy-customized-frameworkehtegg-react-typescript-boilerplateegg-react-webpack-antd-boilerplateegg-react-webpack-asset-boilerplateegg-react-webpack-awesome-boilerplateegg-react-webpack-boilerplateegg-react-webpack-html-boilerplateegg-react-webpack-mpa-boilerplateegg-react-webpack-spa-boilerplateegg-react-asset-boilerplateegg-react-html-boilerplateelectron-local-http-serveregg-jianghuegg-fortressegg-framework-demoegg-framework-wlxhegg-examplessegg-block-releaseeggserveregg-sachikawaegg-sail
3.0.1

1 year ago

2.2.4

1 year ago

3.0.0

2 years ago

2.2.3

6 years ago

2.2.2

6 years ago

2.2.1

6 years ago

2.2.0

6 years ago

2.1.2

7 years ago

2.1.1

7 years ago

2.1.0

7 years ago

2.0.0

8 years ago

1.2.0

8 years ago

1.1.0

8 years ago

1.0.0

9 years ago

0.0.2

9 years ago

0.0.1

9 years ago