Baike.dev
All toolsOnline toolsAI codingTrendingOpen sourceNewsSubmit
Log in
< Back to tools
C

cors

> 编程语言
Open source

Cross-Origin Resource Sharing(CORS) for koa

743 stars0 likes0 views
WebsiteGitHub

About

Cross-Origin Resource Sharing(CORS) for koa

@koa/cors

NPM version Test coverage npm download

Cross-Origin Resource Sharing(CORS) for koa

Installation

bash
$ npm install @koa/cors --save

Quick start

Enable cors with default options:

  • origin: * (v4 and before: the request's Origin header). This means that by default the requests from all origin webpages will be allowed. If you're running a generic API server, this is what you want, but otherwise you should look into changing the default to something more suitable to your application.
  • allowMethods: GET,HEAD,PUT,POST,DELETE,PATCH
javascript
const Koa = require('koa');
const cors = require('@koa/cors');

const app = new Koa();
app.use(cors());

cors(options)

…

Breaking change between 4.0 and 5.0

The default origin is set to *, if you want to keep the 4.0 behavior, you can set the origin handler like this:

javascript
app.use(cors({
  origin(ctx) {
    return ctx.get('Origin') || '*';
  },
}));

License

MIT

Contributors

| fengmk2 | dead-horse | omsmith | jonathanong | AlphaWong | cma-skedulo

| | :---: | :---: | :---: | :---: | :---: | :---: | | CleberRossi | erikfried | j-waaang | ltomes | lfreneda | matthewmueller | PlasmaPower | swain | TyrealHu | xg-wang | lishengzxc | mcohen75

This project follows the git-contributor spec, auto updated at Sat Oct 08 2022 21:35:10 GMT+0800.

Issues· 0 open

View all issuesOpen on GitHub

No open issues yet, or sync has not completed.

> Tags

JavaScript

No comments yet. Be the first to share.

> Details

PublishedAug 1, 2026
UpdatedSep 17, 2026
Category编程语言
PricingOpen source

> Related tools

T
TypeScript
JavaScript 的超集,为前端与全栈提供静态类型
P
Python
通用编程语言,广泛用于 Web、数据与 AI
G
Go
Google 推出的简洁高效系统语言