Registry / web-framework / koa-cors

koa-cors

JSON →
library0.0.16jsnpmunverified

CORS middleware for Koa (v0.0.16). Inspired by node-cors, this middleware adds Cross-Origin Resource Sharing (CORS) headers to Koa responses. It supports all standard CORS options: origin, expose, maxAge, credentials, methods, and headers. It is a simple, lightweight solution for enabling CORS in Koa apps, but note that the package is old and the Koa ecosystem has evolved significantly since v1. Unmaintained since 2016; consider using @koa/cors for modern Koa 2.x.

npm install koa-cors
INSTALL
IMPORT
SIG · KOA-CORS
K
koa-cors
web-frameworkjavascriptv0.0.16
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
const cors = require('koa-cors');
This package is CJS-only and has no default or named exports.

Shows basic Koa app with CORS enabled reflecting request origin.

const Koa = require('koa'); const cors = require('koa-cors'); const app = new Koa(); app.use(cors({ origin: true })); app.use(async ctx => { ctx.body = 'Hello World'; }); app.listen(3000);
Debug
Known issues
gotchakoa-cors is designed for Koa v1 (generator-based middleware). Koa v2 uses async/await and may have compatibility issues.
fix
Use @koa/cors instead, which supports Koa 2.x.
affects: 0.0.0-0.0.16
gotchaPackage unmaintained since 2016. No updates for compatibility with modern Node.js.
fix
Migrate to active alternatives like @koa/cors or koa2-cors.
affects: 0.0.0-0.0.16
Errors
Common errors & fixes
TypeError: app.use() requires a generator function
Koa v2 uses async functions, but koa-cors expects a generator (Koa v1).
fix
Use @koa/cors or wrap with koa-convert: const convert = require('koa-convert'); app.use(convert(cors()));
Upgrade
Version history
0.0.16latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
13 hits · last 30 days
node
12
OpenAI (training)
1
Resources
koa-cors — npm install koa-cors · libregistry