egg-whistle
    TypeScript icon, indicating that this package has built-in type declarations

    1.2.0 • Public • Published

    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

    Keywords

    Install

    npm i egg-whistle

    DownloadsWeekly Downloads

    22

    Version

    1.2.0

    License

    MIT

    Unpacked Size

    15.7 kB

    Total Files

    13

    Last publish

    Collaborators

    • avatar