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 🙏

© 2024 – Pkg Stats / Ryan Hefner

egg-http-proxy-plus

v2.0.1

Published

powerfull proxy middleware plugin for egg

Downloads

15

Readme

egg-http-proxy-plus

支持转发文件上传接口,支持自定义匹配方法,ctx 透传

NPM version Codacy Badge Test coverage npm download License

Sonar

Configure proxy middleware for egg. Use http-proxy-middleware.

Install

# use npm
$ npm i egg-http-proxy-plus --save

# use yarn
$ yarn add egg-http-proxy-plus

Usage

// {app_root}/config/plugin.js
exports.httpProxyPlus = {
  enable: true,
  package: 'egg-http-proxy-plus'
}

Configuration

Proxy /api requests to http://www.example.org

// {app_root}/config/config.default.js
exports.httpProxyPlus = {
  '/api': 'http://www.example.org'
}
// or
exports.httpProxyPlus = [
  {
    origin: '/api',
    options: 'http://www.example.org'
  }
]

A request to /api/users will now proxy the request to http://www.example.org/api/users

If you don't want /api to be passed along, we need to rewrite the path:

// {app_root}/config/config.default.js
exports.httpProxyPlus = {
  '/api': {
    target: 'http://www.example.org',
    pathRewrite: { '^/api': '' }
  }
}
// or
exports.httpProxyPlus = [
  {
    origin: '/api',
    options: {
      target: 'http://www.example.org',
      pathRewrite: { '^/api': '' }
      // ...
    }
  }
]

custom matching

For full control you can provide a custom function to determine which requests should be proxied or not.

// {app_root}/config/config.default.js
exports.httpProxyPlus = [
  {
    origin(pathname, req) {
      return pathname.match('^/api') && req.method === 'GET'
    },
    options: {}
  }
]

http-proxy events

Pay attention to the fourth parameter, the plug-in transparently transmits the ctx context

// {app_root}/config/config.default.js
exports.httpProxyPlus = {
  '/api': {
    target: 'http://www.example.org',
    onProxyReq(proxyReq, req, res, ctx) {
      if (req.method.toLowerCase() === 'post') {
        const token = ctx.cookies.get('access_token')
        token && proxyReq.setHeader('authorization', token)
      }
    }
  }
}

For more advanced usages, checkout http-proxy-middleware options documentation.

Questions & Suggestions

Please open an issue here.

License

MIT