# mock **Repository Path**: hybsir/mock ## Basic Information - **Project Name**: mock - **Description**: No description available - **Primary Language**: Unknown - **License**: Not specified - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2019-09-12 - **Last Updated**: 2023-12-27 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README ## hyb-mock 用于启动mock服务器,并提供log输出功能 ### Installation ​ npm install hyb-mock ![]() ## **options** ``` Options: -v, --version output the current version -p, --port server port (default: 8080) -o, --host server host (default: "localhost") -m, --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为对象 ```js 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为方法 ```js 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 ```