0.2.4 • Published 4 years ago

http-proxy-404 v0.2.4

Weekly downloads
1
License
ISC
Repository
github
Last release
4 years ago

http-proxy-404mock 是一个基于http-proxy-middleware 开发的node代理服务器

Http-proxy-404 is a node proxy server based on http-proxy-middleware

你可以用它做什么呢?

What can you do with it?

你可以配置一堆不同环境的接口服务地址

You can configure a bunch of interface service addresses for different environments.

它会自动嗅探接口在当前配置的服务器地址中 请求的response的状态是否为404,如果请求的状态是404,它会往下一个地址中继续请求,直至成功

It will automatically sniff the interface to request the response status in the currently configured server address is 404,If the status of the request is 404, it will continue the request to the next address until it succeeds

$ npm install http-proxy-404 --save-dev

or

$ yarn add http-proxy-404 -D

step1: create serve.js

const Proxy404 = require('http-proxy-404')

new Proxy404({
  port: 8081,
  apiReg: '/api*',
  targetList: [
    'target host1',
    'target host2',
    'target host3'
  ],
  '404func': function(res) {
    if(!res.response) {
      return true
    }
  }
})

step2: Configuring webpack

proxy: {
    '/': {
      target: "http://x.x.x.x:port", // Please fill in the proxy service address output by http-proxy-404
      ws: false,
      changeOrigin: true,
    }
  }

step3: run serve.js

nodemon serve.js

or in your package.json

"scripts": {
    "dev": "webpack-dev-server xxx & nodemon serve.js"
  },
NameRequiredTypeDefaultDescription
portfalse{Number}8081Proxy service port,If the port is occupied will port++ and until the port is available
logfalse{Boolean}trueWhether to print the log
apiRegtrue{RegExp}nullInterface matching rule
changeOriginfalse{Boolean}truechanges the origin of the host header to the target URL
wsfalse{Boolean}falseif you want to proxy websockets
404funcfalse{Function}nullCustom function used to determine 404;Return true means you want to proxy next;Return false instead
200funcfalse{Function}nullCustom function used to determine 200;Return true means you want to proxy next;Return false instead;If you return a string, it will be defaulted to the address of the mandatory proxy
securefalse{Boolean}falseif you want to verify the SSL Certs

2019-11-25:

  • 新增 参数配置 200func
  • 新增自动检测端口占用功能,并自动分配可用端口
0.2.4

4 years ago

0.2.3

4 years ago

0.2.2

4 years ago

0.2.1

4 years ago

0.2.0

4 years ago

0.1.9

4 years ago

0.1.8

5 years ago

0.1.7

5 years ago

0.1.6

5 years ago

0.1.4

5 years ago

0.1.3

5 years ago

0.1.2

5 years ago