0.0.15 • Published 7 years ago

ejs-mock v0.0.15

Weekly downloads
1
License
MIT
Repository
github
Last release
7 years ago

NPM version

ejs Mock

本地数据模拟服务,使用ejs来解析数据模版 local data mock server, use ejs render response data template

Installation and usage

$ npm install ejs-mock --save-dev

You should then setup a configuration file:

$ ./node_modules/.bin/ejs-mock --init

After that, you can run ejs-mock

$ ./node_modules/.bin/ejs-mock

open dashboard 🎛 http://localhost:8080/ejs-mock-admin

Configuration

After running

$ ./node_modules/.bin/ejs-mock --init

you'll have a .ejsmockrc file in your directory. In it, you'll see some rules configured like this:

{
  "name": "app name",
  "port" : "8080",
  "mockPath": "./mock",
  "rootPath": "./dist"
}

Create an mock

./mock 文件夹中添加json接口配置文件 list.json, like this

{
  "name": "list",
  "describe": "a list",
  "url": "/list",
  "method": "GET",
  "dataType": "JSON",
  "responseKey": "firstKey",
  "responseOptions": {
    "firstKey": {
      "desc": "only one",
      "path": "./list/firstData.json"
    },
    "secondKey": {
      "desc": "multiple items",
      "path": "./list/secondData.json"
    }
  }
}

对应 list.json 配置,在 ./mock/list 中创建接口数据文件 firstData.json, like this

{
  "data": [{
    "text": "hello world"
  }],
  "state": {
    "code": 200,
    "msg": "success"
  }
}

After running

$ ./node_modules/.bin/ejs-mock

🎈visit admin http://localhost:8080/ejs-mock/admin also running

$ ./node_modules/.bin/ejs-mock demo

visit example http://localhost:8080/

Feature:

  • 常规数据返回
  • 图片上传
  • 异常数据返回
  • 数据切换
0.0.15

7 years ago

0.0.14

7 years ago

0.0.13

7 years ago

0.0.12

7 years ago

0.0.11

7 years ago

0.0.10

7 years ago

0.0.8

7 years ago

0.0.7

7 years ago

0.0.6

7 years ago

0.0.1

7 years ago