我使用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
});
});
代理功能有一些功能无法解决,所以我想记录代理完成的实际请求。
我怎样才能做到这一点?
答案 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];
}
});
});