-

-

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);
最后修改:2024 年 07 月 09 日
如果觉得我的文章对你有用,请随意赞赏