Code Monkey home page Code Monkey logo

egg-development-proxyagent's Introduction

egg-development-proxyagent

NPM version build status Test coverage David deps Known Vulnerabilities npm download

Nowadays lots of services are built upon HTTP protocol. So it's quite common to invoke backend services based on HTTP.

There is a built-in httpclient in Egg framework so that we can use it to invoke HTTP services easily.

This plugin provides a way of capturing HTTP request for debugging purpose.

DEPRECATED

This plugin is deprecated, instead, you just need to add below code to config.local.js

// config.local.js
module.exports = () => {
  const config = {};

  // add http_proxy to httpclient
  if (process.env.http_proxy) {
    config.httpclient = {
      request: {
        enableProxy: true,
        rejectUnauthorized: false,
        // proxy: process.env.http_proxy,
      },
    };
  }

  return config;
}

then start your application by:

$ http_proxy=http://127.0.0.1:8888 npm run dev

Install

npm i egg-development-proxyagent --save-dev
// config/plugin.local.js
exports.proxyagent = {
  enable: true,
  package: 'egg-development-proxyagent',
};

Usage

This plugin will take effect only in local env. Because it overrides the agent and httpsAgent of httpclient, so it will work for every request. And also you can delegate HTTPS requests via HTTP.

http_proxy or HTTP_PROXY environment variable will be used if set in Bash. Or you can specify it when you start app:

$ http_proxy=http://127.0.0.1:8888 node index.js

Capturing HTTPS Traffic

By default the http_proxy(or HTTP_PROXY) mentioned above will be passed to httpsAgent of urllib, and rejectUnauthorized = false will be set.

However, when using self-signed certificate we need to configure the certificate, shown as follows:

ca String | Buffer | Array - An array of strings or Buffers of trusted certificates. If this is omitted several well known "root" CAs will be used, like VeriSign. These are used to authorize connections. Notes: This is necessary only if the server uses the self-signed certificate

// config/config.default.js
exports.proxyagent = {
  ca: 'xxxxxxxxxxxx',
};

Capturing Tool

Note: Capturing tool is not in this plugin, you can use one of them below:

  • charles
  • fiddler
  • anyproxy is a capturing tool writtern in node. It provides a web console, it's a good replacement of charles.
$ npm install anyproxy -g
$ anyproxy --port 8888
$ open http://localhost:8002

Screenshot:

anyproxy

Questions & Suggestions

Please open an issue here.

License

MIT

egg-development-proxyagent's People

Contributors

atian25 avatar luicfer avatar shaoshuai0102 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Forkers

luicfer wooodhead

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.