Giter VIP home page Giter VIP logo

ejs-mock's Introduction

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:

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

ejs-mock's People

Contributors

ibone avatar

Watchers

James Cloos avatar

Forkers

wheung

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.