Add responseInterceptor handler to easily intercept and manipulate responses. Responses compressed with brotli, gzip and deflate are decompressed automatically.
install beta: npm install http-proxy-middleware@1.2.0-beta.2 or yarn add http-proxy-middleware@1.2.0-beta.2
TL;DR
const { createProxyMiddleware, responseInterceptor } = require('http-proxy-middleware');
const proxy = createProxyMiddleware({
/**
* IMPORTANT: avoid res.end being called automatically
**/
selfHandleResponse: true, // res.end() will be called internally by responseInterceptor()
/**
* Intercept response and replace 'Hello' with 'Goodbye'
**/
onProxyRes: responseInterceptor(async (responseBuffer, proxyRes, req, res) => {
const response = responseBuffer.toString('utf-8'); // convert buffer to string
return response.replace('Hello', 'Goodbye'); // manipulate response and return the result
}),
});
documentation: https://github.com/chimurai/http-proxy-middleware/tree/response-interceptor#intercept-and-manipulate-responses
recipes: https://github.com/chimurai/http-proxy-middleware/blob/response-interceptor/recipes/response-interceptor.md#readme
Add
responseInterceptorhandler to easily intercept and manipulate responses. Responses compressed withbrotli,gzipanddeflateare decompressed automatically.install beta:
npm install http-proxy-middleware@1.2.0-beta.2oryarn add http-proxy-middleware@1.2.0-beta.2TL;DR
documentation: https://github.com/chimurai/http-proxy-middleware/tree/response-interceptor#intercept-and-manipulate-responses
recipes: https://github.com/chimurai/http-proxy-middleware/blob/response-interceptor/recipes/response-interceptor.md#readme