onError

订阅 http-proxy 的 error 事件.

var proxyMiddleware = require("http-proxy-middleware");

var onError = function (err, req, res) {
    console.log('Something went wrong.');
    console.log('And we are reporting a custom error message.');
};

var options = {target:'http://localhost:3000', onError: onError};

var proxy = proxyMiddleware('/api', options);

onProxyReq

订阅 http-proxy 的 proxyReq 事件.

var proxyMiddleware = require("http-proxy-middleware");

var onProxyReq = function (proxyReq, req, res) {
    // add new header to request
    proxyReq.setHeader('x-added', 'foobar');
};

var options = {target:'http://localhost:3000', onProxyReq: onProxyReq};

var proxy = proxyMiddleware('/api', options);

onProxyRes

订阅 http-proxy 的 proxyRes 事件.

var proxyMiddleware = require("http-proxy-middleware");

var onProxyRes = function (proxyRes, req, res) {
    // add new header to response
    proxyRes.headers['x-added'] = 'foobar';

    // remove header from response
    delete proxyRes.headers['x-removed'];
};

var options = {target:'http://localhost:3000', onProxyRes: onProxyRes};

var proxy = proxyMiddleware('/api', options);

results matching ""

    No results matching ""