webpack devServer代理打印日志

proxy: {
    '/api': {
      target: 'http://api.xxx.com',
      //去除api头,即去除context,不加pathRewrite,则不去除任何
      pathRewrite: {'^/api': ''},
      changeOrigin: true,
      logLevel: 'debug',
      onProxyReq: (proxyReq, req) => {
        // http请求
        console.log('[HPM] %s %s %s %s', req.method, req.originalUrl, '->', req.url);
      },
      onProxyReqWs(proxyReq, req, socket, options, head) {
        // websocket请求(单个TCP连接上进行全双工通信的协议)
        console.log('[HPM] %s %s %s %s', req.method, '-', req.url);
      }
    }
}

 

posted @ 2023-08-03 14:59  全玉  阅读(1408)  评论(0编辑  收藏  举报