Socket
Socket
Sign inDemoInstall

egg-cors

Package Overview
Dependencies
2
Maintainers
5
Versions
14
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    egg-cors

cors plugin for egg


Version published
Weekly downloads
10K
decreased by-7.6%
Maintainers
5
Install size
28.8 kB
Created
Weekly downloads
 

Changelog

Source

3.0.0 (2023-12-11)

⚠ BREAKING CHANGES

  • drop Node.js < 14

Features

2.2.3 / 2019-11-14

fixes

2.2.2 / 2019-10-25

fixes

others

2.2.1 / 2019-10-22

fixes

  • [499c2b1] - fix: second-level domain and port support misjudgement (#20) (Khaidi Chu <i@2333.moe>)

2.2.0 / 2019-03-11

features

2.1.2 / 2018-11-30

  • chore: typings of origin params (#18)

2.1.1 / 2018-10-01

  • deps: update (#17)
  • chore: add types of cors option. (#15)
  • docs: update readme (#16)

2.1.0 / 2018-07-11

others

2.0.0 / 2017-11-23

others

1.2.0 / 2017-07-24

  • deps: update deps (#8)
  • feat: add config for Access-Control-Allow-Origin (#7)

1.1.0 / 2017-03-24

  • feat: update to egg@1.0 and docs fix (#6)
  • fix: adjust with new test (#4)

1.0.0 / 2016-11-04

  • chore: update deps and test on node v7 (#3)
  • doc: add configuration information on how to pass in domain whitelist (#2)
  • test: add tests (#1)

0.0.2 / 2016-07-15

  • init

Readme

Source

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.

Keywords

FAQs

Last updated on 11 Dec 2023

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc