Socket
Socket
Sign inDemoInstall

@kitten-team/koa-cache-proxy

Package Overview
Dependencies
55
Maintainers
5
Versions
2
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    @kitten-team/koa-cache-proxy

Proxy middleware for koa


Version published
Maintainers
5
Install size
5.83 MB
Created

Changelog

Source

1.0.3 (2018-09-10)

<a name="1.0.2"></a>

Readme

Source

koa-cache-proxy

这个项目 fork 自koa-proxy,在保留原有 api 的基础上拓展了其他功能,原始 api 参考原文档,下文只描述改动的部分

安装

npm install koa-cache-proxy -S

新特性

  •  使用 async/await 代替 generate,不再支持低版本 koa2 和 node
  • 增加 hook 功能对某些自定义 url 做响应
  • 增加 cache 功能,可将反向代理的资源缓存在内存中,减少反向代理的次数

用例

  • hook 功能
const proxy = require('koa-cache-proxy')
...
app.use(
  proxy({
    host: 'https://alicdn.com',
    match: /^\/example(\/)?/,
    hooks: [
      {
        path: '/example/LfkFyA2UCcsn8NIr', //随便起的一个url
        handle(ctx) {
          // do something
        },
      },
    ],
 })
)
...

使用 hook 功能, hook 中定义的链接只会在 match 匹配的前提下生效

  • cache 功能
const proxy = require('koa-cache-proxy')
...
app.use(
  proxy({
    host: 'https://alicdn.com',
    match: /^\/example(\/)?/,
    cache: true //缓存所有,
    // cache: /\.html$/ 缓存所有html结尾文件
    // cache(path) { return false } 动态决定是否缓存
 })
)
...

cache 缓存时会连同 response header 也一并缓存

新增属性

使用此插件,在 koa 的 ctx 中将新增以下属性

  • ctx.isCacheable

ctx.path 是否符合缓存规则

LICENSE

Licensed under the MIT license.

Keywords

FAQs

Last updated on 10 Sep 2018

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