webpack-dev-server proxy config

proxyTable: {
      '/': {
        target: 'http://childstar.test',
        changeOrigin: true,
        secure: false,
        bypass(req, res, proxyOption) {
          var body = ''
          req.on('data', (data) => {
            body += data

            if (body.length > 1e6) {
              req.connection.destroy()
              console.error('body length ' + body.length + 'is to long')
            }
          })

          console.log('headers ' + JSON.stringify(req.headers))
          console.log('proxy ' + proxyOption.target + req.originalUrl)
          console.log('method ' + req.method)
          console.log('query ' + JSON.stringify(req.query))
          console.log('params ' + JSON.stringify(req.params))

          req.on('end', () => {
            if (body === '') { body = '{}' }
            console.log('raw body ' + body)
            console.log('')
          })
        }
      }
    },
评论数量: 0

0
点赞
235
浏览
0
评论

贡献 58