http-proxy-404

0.2.4 • Public • Published

http-proxy-404

just proxy serve,proxy 404 interface to target servers

Introduction

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

Install

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

or

$ yarn add http-proxy-404 -D

Usage

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"
  },

options

Name Required Type Default Description
port false {Number} 8081 Proxy service port,If the port is occupied will port++ and until the port is available
log false {Boolean} true Whether to print the log
apiReg true {RegExp} null Interface matching rule
changeOrigin false {Boolean} true changes the origin of the host header to the target URL
ws false {Boolean} false if you want to proxy websockets
404func false {Function} null Custom function used to determine 404;Return true means you want to proxy next;Return false instead
200func false {Function} null Custom 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
secure false {Boolean} false if you want to verify the SSL Certs

update log

2019-11-25:

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

Package Sidebar

Install

npm i http-proxy-404

Weekly Downloads

1

Version

0.2.4

License

ISC

Unpacked Size

8.25 kB

Total Files

4

Last publish

Collaborators

  • qiankun