代码之家  ›  专栏  ›  技术社区  ›  Michał Pietraszko

如何防止从哈皮的特定路线记录响应。js用得好吗?

  •  0
  • Michał Pietraszko  · 技术社区  · 9 年前

    我用下面的方法挤压

    // ...
    {
      module: 'good-squeeze',
      name: 'Squeeze',
      args: [
        {
          log: '*',
          response: '*',
          request: '*'
        }
      ]
    },
    // ...
    

    localhost:3000/health

    2016-09-28T10:50:26.652, [response] http://0.0.0.0:3000: post /health {} 200 (321ms)
    

    如何阻止此特定路由的响应日志记录?

    1 回复  |  直到 9 年前
        1
  •  0
  •   Michał Pietraszko    9 年前

    似乎不可能使用 good-squeeze 所以我创建了自己的好插件,当日志与 /health 路线

    const Stream = require('stream');
    
    class ExcludePath extends Stream.Transform {
    
      constructor() {
        super({ objectMode: true });
      }
    
      _transform(data, enc, next) {
    
        if (data.route === '/health') {
          return next();
        }
    
        return next(null, data);
      }
    
    }
    
    module.exports = ExcludePath;