@swzj/mock
v0.1.3
Published
快速开启 mock api 服务器
Downloads
3
Readme
@swzj/mock 随启随用的 mock api 服务器
随时随地将你的当前目录变成一个 mock api 服务器的根目录。
安装及使用
通过 npm -g
将其安装为命令行工具。
npm install @swzj/mock -g
// 启动服务(8000 为默认端口,当前文件夹为根目录)
$ s-mock
// 开启 mock api 服务
$ s-mock -m
// 设置服务端口
$ s-mock -p 8000
// 静默方式启动(不自动打开浏览器)
$ s-mock -s
// 设置主机名
$ s-mock -h localhost -p 8888
// 设置根目录
$ s-mock -d ./mock
// 启用 html5 history 路由模式
$ s-mock -f /index.html
// 开启服务代理
$ s-mock -x/--proxy http://localhost:7000/api
// 根据接口路径创建文件夹及 json 文件
$ s-mock -c/--create /test/user
若根目录下有文件:'test/user.json',user.json 则为请求 '/test/user' 提供数据源。
此时以任何请求方式请求 'http://x.x.x.x:8000/test/user' 都将得到 user.json 文件数据作为响应。
帮助
$ s-mock --help
Usage:
s-mock --help // 打印帮助信息
s-mock // 8000 为默认端口,当前文件夹为根目录
s-mock 8888 // 将 8888 作为服务端口
s-mock -m // 开启 mock api 服务
s-mock -p 8989 // 将 8989 作为服务端口
s-mock -s // 不自动打开浏览器(静默服务)
s-mock -h localhost // 设置 localhost 为主机名
s-mock -d /home // 将 /home 作为根目录
s-mock -l // 打印日志
s-mock -f /index.html // 启用 html5 history 路由模式,404 时回退到 /index.html
s-mock -x/--proxy http://localhost:7000/api // 支持网址, webpack.config.js 或自定义配置文件
s-mock -c/--create /test/user // 根据接口路径创建文件夹及 json 文件'
Fork
anywhere 功能增强