npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

koa2-origin-cors

v1.0.2

Published

cors middleware for koa2 server

Readme

cors middleware for koa2-server

带有域名拦截功能的koa2-cors中间件

Features

  • 黑名单域名模式
  • 白名单域名模式
  • 全局允许模式 (允许所有请求跨域并携带Credentials)
  • 基本跨域请求支持

Example

 const Koa = require('koa')
 const cors = require('koa2-origin-cors')  
 
 const server = new Koa()
 server.use(cors())

模式说明

allowAll

允许所有跨域请求并允许其携带Credentials凭据

server.use(cors({allowAll: true}))

blackList

blackList中的域名将被阻止访问

const corsOptoins = {
    blackList: [
        'test.dev.org', '123.22.11.33'
    ],
    terminationCode: 404 // [可选]拦截时返回Status403
    
}
server.use(corsOptions)

whiteList

只有白名单中的域名允许访问 注意本地非服务器模式访问时whiteList中添加String(null)

const corsOptions = {
    whiteList: [
        '192.168.1.123', 'null'
    ],
    terminationCode: 403 // [可选]拦截时返回Status
}
server.use(corsOptions)

origin

设置允许哪个域名下的访问跨域

server.user({
    origin: '192.168.1.110'
})

功能参数说明

  • allowAll {Boolean} 允许所有站点跨域并携带凭据

  • blackList {Array} 黑名单列表 黑名单中的域名将被拒绝访问

  • whiteList {Array} 白名单列表 只有白名单中的域名允许访问

  • origin {String | Function} 请求头Origin

  • credentials {Boolean} 允许携带凭据

  • terminationCode {Number} 拒绝返回httpStatus

  • vary {Boolean} 是否强制不同网站使用不同缓存 (a.git, b.git)

拦截优先级 allowAll > blackList > whiteList > origin

说明

初衷是想做一个域名拦截中间件,但与跨域设置使用2个中间件略显累赘,且与cors中有多处相似判断逻辑,所以把两部分功能整合到一起

整合了一部分koa2-cors 的源码