记录使用gulp-connect完成的所有请求

时间:2015-03-05 13:49:56

标签: node.js gulp

我使用gulp-connect和proxy-middleware。

var proxy_function = function(connect, o) {
    return [

        ,(function() {
        var url = require('url');
        var proxy = require('proxy-middleware');
        var options = url.parse(a);
        options.route = b;
        return proxy(options);
    })() ];
};

gulp.task('connect', function() {
    connect.server({
        port: '8002',
        root: build_dest,
        middleware: proxy_function
    });
});

代理功能有一些功能无法解决,所以我想记录代理完成的实际请求。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

试试这个:

var gutil = require('gulp-util');
var gulp = require('gulp');
var connect = require('gulp-connect');

function accessLog(req, res, next) {
  gutil.log(req.method, req.url, 'HTTP/' + req.httpVersion, res.statusCode);
  next();
}

gulp.task('connect', function() {
  connect.server({
    port: 8002,
    root: build_dest,
    middleware: function(connect, opt) {
      return [accessLog];
    }
  });
});