Add responseInterceptor handler to easily intercept and manipulate responses. Responses compressed with brotli, gzip and deflate are decompressed automatically.
install beta: npm install [email protected] or yarn add [email protected]
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 [email protected]oryarn add [email protected]TL;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