1.4.3 • Published 5 months ago

hyb-mock v1.4.3

Weekly downloads
3
License
MIT
Repository
-
Last release
5 months ago

hyb-mock

用于启动mock服务器,并提供log输出功能

Installation

​ npm install hyb-mock

npm.io

options

Options:
  -v, --version                 output the current version
  -p, --port <port>             server port (default: 8080)
  -o, --host <host>             server host (default: "localhost")
  -m, --mockPath <mockPath>     read mockPath (default: "mocks")
  -l, --logPath [logPath]       output log (default: "") 
  -r, --proxyPath [proxyPath]   server proxy (default: "")
  -h, --help                    output usage information

port

​ 服务开启端口为8000,默认8080

    mock --port 8000

host

​ 服务开启地址为127.0.0.3,默认localhost

    mock --host 127.0.0.3

mockPath

mackPath为读取接口文件地址.以当前工作目录process.cwd()为相当路径,默认为mocks文件。

mockPath下文件应导出一个对象key 为接口请求地址,value有俩种类型,1.对象,内容为响应报文,支持mockjs语法。2.方法,第一个参数为请求报文,return的内容为响应报文

  1. value为对象
module.exports = {
    "/user": {
        // mock配置项,目前只支持延迟时间
        mockConfig: {
            delay: 6000
        },
        'a|3-5': 'a',
        'list|10': [{ 'id|+1': 0 }]
    },
    "/name": {
        'b|3-5': 'a',
        'list|10': [{ 'id|+1': 0 }]
    }
}

2.value为方法

module.exports = {
    "/name": function(body) {
        if (body.name === '1') {
            return {
                'c|3-5': 'a',
                'list|10': [{ 'id|+1': 0 }]
            }
        }
    }
}

logPath

日志输出路径地址,以当前工作目录process.cwd()为相当路径下面的logs/dora文件。默认不输出日志

mock --logPath logs/dora

proxyPath

http请求代理地址,请求代理到http://localhost:3000。默认不进行代理

mock --proxyPath http://localhost:3000
1.4.3

5 months ago

1.2.3

5 years ago

1.2.2

5 years ago

1.2.1

5 years ago

1.2.0

5 years ago

1.1.1

5 years ago

1.1.0

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago