connect-mock-middleware
Very easy to use mock middleware
- Support mockjs syntax
- Support json、jsonp
- Modify the mock data and do not need to restart
Install
npm install connect-mock-middleware
Usage
1. add middleware
const express = const path = const connectMockMiddleware = const app = app app
2. write mock file
Suppose I have two requests
get /api/xxx
post /api/<id>/123
<id>
link express router/api/:id/123
, it means that the value changes
The file structure is as follows
mock
└─get
├─api_xxx.js
post
└─api_@id_xxx.js
example: api_xxx.js
module { // params, the path parameter // query, get query parameter // body, post submit parameter return code: 1 data: back msg: '' }
Config
- prefix
<string|string[]|function>
: Intercepting API prefixes, default/*
on behalf of all - callback
<string>
: jsonp callback name, defaultcallback
Notice: you also need to configure your app
app