1 | # mock-servicer - 用于提供模拟数据的node服务器。
|
2 |
|
3 | <p>
|
4 | <a href="https://hai2007.gitee.io/npm-downloads?interval=7&packages=mock-servicer"><img src="https://img.shields.io/npm/dm/mock-servicer.svg" alt="downloads"></a>
|
5 | <a href="https://packagephobia.now.sh/result?p=mock-servicer"><img src="https://packagephobia.now.sh/badge?p=mock-servicer" alt="install size"></a>
|
6 | <a href="https://www.jsdelivr.com/package/npm/mock-servicer"><img src="https://data.jsdelivr.com/v1/package/npm/mock-servicer/badge" alt="CDN"></a>
|
7 | <a href="https://www.npmjs.com/package/mock-servicer"><img src="https://img.shields.io/npm/v/mock-servicer.svg" alt="Version"></a>
|
8 | <a href="https://github.com/hai2007/mock-servicer/blob/master/LICENSE"><img src="https://img.shields.io/npm/l/mock-servicer.svg" alt="License"></a>
|
9 | <a href="https://github.com/hai2007/mock-servicer">
|
10 | <img alt="GitHub repo stars" src="https://img.shields.io/github/stars/hai2007/mock-servicer?style=social">
|
11 | </a>
|
12 | </p>
|
13 |
|
14 | ## Issues
|
15 | 使用的时候遇到任何问题或有好的建议,请点击进入[issue](https://github.com/hai2007/mock-servicer/issues)!
|
16 |
|
17 | ## 如何使用?
|
18 |
|
19 | ```
|
20 | npm install mock-servicer
|
21 | ```
|
22 |
|
23 | 安装好了以后,在需要的地方引入:
|
24 |
|
25 | ```js
|
26 | const MockServicer = require('mock-servicer');
|
27 |
|
28 | MockServicer({
|
29 |
|
30 | // 请求端口,默认8080
|
31 | port: 30000,
|
32 |
|
33 | // 数据处理方法
|
34 | handler: function (options, Mock) {
|
35 |
|
36 | return {
|
37 |
|
38 | // 状态码
|
39 | status: 200,
|
40 |
|
41 | // 数据
|
42 | // 可以根据options来判断应该返回什么样的数据
|
43 | data: Mock.mock({
|
44 | // 这里可以借助mock的方法来生成模拟数据
|
45 | // 或者使用缓存数据
|
46 | })
|
47 |
|
48 | };
|
49 |
|
50 | }
|
51 |
|
52 | });
|
53 | ```
|
54 |
|
55 | 开源协议
|
56 | ---------------------------------------
|
57 | [MIT](https://github.com/hai2007/mock-servicer/blob/master/LICENSE)
|
58 |
|
59 | Copyright (c) 2021 [hai2007](https://hai2007.gitee.io/sweethome/) 走一步,再走一步。
|