-
-
const application = require('express')();
const { createProxyMiddleware, responseInterceptor } = require('http-proxy-middleware');
const _ = require("lodash");
application.use(
createProxyMiddleware({
changeOrigin: true,
selfHandleResponse: true,
target: 'https://nian.jishu.xin',
on: {
proxyRes: responseInterceptor(async (buffer, proxyResponse, request) => {
//
console.log({
request: _.pick(request, ['hostname', 'path', 'method', 'headers']),
proxyResponse: _.pick(proxyResponse, ['statusCode', 'headers']),
buffer: proxyResponse.headers['content-type'].startsWith('application/json') ? buffer.toString() : undefined,
});
//
return buffer;
}),
},
}),
);
application.listen(80);