|
|
2 năm trước cách đây | |
|---|---|---|
| .. | ||
| app | 2 năm trước cách đây | |
| config | 2 năm trước cách đây | |
| History.md | 2 năm trước cách đây | |
| LICENSE | 2 năm trước cách đây | |
| README.md | 2 năm trước cách đây | |
| app.js | 2 năm trước cách đây | |
| index.d.ts | 2 năm trước cách đây | |
| package.json | 2 năm trước cách đây | |
CORS plugin for egg, based on @koa/cors.
$ npm i egg-cors --save
// {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' ],
};
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.
Only in safe domain list support CORS when security plugin enabled.
Please open an issue here.