Skip to content

Request proxy middleware for egg framework.based on http-proxy

License

Notifications You must be signed in to change notification settings

SliverYuki/egg-proxifier

Repository files navigation

Egg Proxifier

[email protected]/next middlware for http proxy

Powered by http-proxy.

Style Guide Airbnb JavaScript Style Guide() {.

Installation

$ npm install egg-proxifier --save

Options

Supports all of http-proxy options

NOTE:

options.rewrite - function, rewrite the path

options.log - boolean, print a log message

http-proxy events

Supports all of http-proxy events

options.events = {
  error(err, req, res) { },
  proxyReq(proxyReq, req, res) { },
  proxyRes(proxyRes, req, res) { }
}

Usage

// middleware/http_proxy.js
const proxy = require('egg-proxifier')

module.exports = (options, app) => proxy('/proxy', {
  target: app.config.host,
  changeOrigin: true,
  rewrite: path => path.replace('/proxy', ''),
  events: {
    error(err, req, res) { },
    proxyReq(proxyReq, req, res) { },
    proxyRes(proxyRes, req, res) { }
  },
})
// app.js
module.exports = app => {
  app.config.coreMiddleware.unshift('httpProxy')
  // ...
}

About

Request proxy middleware for egg framework.based on http-proxy

Resources

License

Stars

Watchers

Forks

Packages

No packages published