Using whistle in egg
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
app
config
lib
test
.eslintignore
.eslintrc
.gitignore
.travis.yml
History.md
LICENSE
README.md
agent.js
app.js
appveyor.yml
index.d.ts
package.json

README.md

egg-whistle

NPM version build status Test coverage Appveyor status David deps Known Vulnerabilities

Using whistle in egg application.

What is whistle

Whistle is a great web debugging tool based on Nodejs.

see https://github.com/avwo/whistle

Install

$ npm install egg-whistle --save

or

$ yarn add egg-whistle --save

Usage

// config/plugin.js

exports.whistle = {
  enable: true,
  env: [ 'local', 'test' ],
  package: 'egg-whistle',
};

Starting the egg application and visit http://{your app host}:{your app port}/__whistle__

eg.

$ npx egg-bin dev

open whistle

$ open http://127.0.0.1:7001/__whistle__

After application started, The http request client in egg ( app.httpclient or ctx.httpclient ) will send requests through whistle proxy, and capture the request info in whistle dashboard.

Proxy Custom Requests

egg-whistle only proxy the requests sent by app.httpclient or ctx.httpclient ( includes ctx.curl or app.curl ) in egg by default. If you want to proxy your own requests( like http.request or websocket ), app.whistle.proxyAgent may works for you.

http

// app.js

const http = require('http');
module.exports = app => {
  app.whistle.on('ready', () => {
    http.request('http://xxx.com/xxx', { agent: app.whistle.proxyAgent });
  });
};

websocket

// app.js

const ws = require('WebSocket');
module.exports = app => {
  app.whistle.on('ready', () => {
    const socket = new WebSocket('ws://xxx.com/xxx', {
      agent: app.whistle.proxyAgent,
    });
  });
};

global agent

// app.js

const http = require('http');
module.exports = app => {
  app.whistle.on('ready', () => {
    http.globalAgent = app.whistle.proxyAgent;
  });
};

Configuration

// config/config.default.js

exports.whistle = {
  // route: '/__whistle__', // whistle url
  // ignore: undefined, // Array<RegExp> | RegExp, eg. /\/test\/.*/ or [ /\/test\/.*/ ]
  // storage: path.resolve(appInfo.root, 'logs/whistle'),
  // timeout: 3600,
  // see https://github.com/avwo/whistle to know more configuration
}

plugin config

  • route whistle dashboard path
  • ignore ignore urlArray<RegExp> | RegExp, eg. /\/test\/.*/ or [ /\/test\/.*/ ] only works for httpclient in egg.

whistle config

See https://github.com/avwo/whistle#install--setup ( support the most configuration of whistle except localUIHost host port uiport version )

Lincense

MIT