mock-service-cli 3.1.6 → 3.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -0
- package/lib/mockServer.js +5 -4
- package/package.json +2 -1
package/README.md
CHANGED
|
@@ -14,6 +14,11 @@
|
|
|
14
14
|
|
|
15
15
|
**简易轻量**、**B/S 架构**、**0 秒启动**的本地命令行 Mock 服务套件, 支持热更新,对于开发调试 mock 数据很实用,能提高前端开发者的开发效率。支持 `GET`,`POST`,`PUT`,`DELETE`,`PATCH`,`OPTIONS`,`COPY`,`LINK`,`UNLINK`,`PURGE` 等常用请求类型,无需布署后端,可能是本地最好用的 Mock 工具之一。
|
|
16
16
|
|
|
17
|
+
特性功能:
|
|
18
|
+
|
|
19
|
+
- 支持统计 mock 的文件数量和 mock 请求数量
|
|
20
|
+
- 支持终端打开 mock 文件的所在位置
|
|
21
|
+
|
|
17
22
|
#### Mock Server - 本地 Mock 服务器
|
|
18
23
|
|
|
19
24
|
支持以下常见业务场景:
|
package/lib/mockServer.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const express = require('express'), // 引入express
|
|
2
|
+
bodyParser = require('body-parser'),
|
|
2
3
|
fs = require('fs'),
|
|
3
4
|
os = require('os'),
|
|
4
5
|
path = require('path'),
|
|
@@ -109,7 +110,7 @@ const composeRouteFromJsFile = function (file) {
|
|
|
109
110
|
colors.grey(`path ${String(++count).padStart(3, ' ')}: `),
|
|
110
111
|
colors.cyan(reqMethod.padEnd(8, ' ')),
|
|
111
112
|
colors.cyan(reqUrl),
|
|
112
|
-
colors.
|
|
113
|
+
colors.grey(typeof fileObject[item])
|
|
113
114
|
);
|
|
114
115
|
log.assert(typeof app[reqMethod] === 'function', colors.red(`${file}, ${reqMethod}`));
|
|
115
116
|
if (typeof fileObject[item] === 'function') {
|
|
@@ -154,7 +155,7 @@ const parseMockFiles = function (specialDir = '../mock') {
|
|
|
154
155
|
colors.grey(`path ${String(++count).padStart(3, ' ')}: `),
|
|
155
156
|
colors.cyan(method.padEnd(8, ' ')),
|
|
156
157
|
colors.cyan(apiUrl),
|
|
157
|
-
colors.
|
|
158
|
+
colors.grey(typeof fileObject[method])
|
|
158
159
|
);
|
|
159
160
|
log.assert(typeof app[method] === 'function', colors.red(`${filePath}, ${method}`));
|
|
160
161
|
app[method](apiUrl, function (req, res) {
|
|
@@ -172,8 +173,8 @@ const parseMockFiles = function (specialDir = '../mock') {
|
|
|
172
173
|
}
|
|
173
174
|
};
|
|
174
175
|
|
|
175
|
-
// 允许跨域
|
|
176
|
-
app.use(
|
|
176
|
+
app.use(crossDomain()); // 允许跨域
|
|
177
|
+
app.use(bodyParser.json()); // 解析body
|
|
177
178
|
|
|
178
179
|
if (process.env.SPECIFIED_FILE) {
|
|
179
180
|
composeRouteFromJsFile(process.env.SPECIFIED_FILE);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "mock-service-cli",
|
|
3
|
-
"version": "3.1.
|
|
3
|
+
"version": "3.1.8",
|
|
4
4
|
"description": "🦅 Local mock server",
|
|
5
5
|
"main": "./lib/mockServer.js",
|
|
6
6
|
"bin": {
|
|
@@ -45,6 +45,7 @@
|
|
|
45
45
|
"license": "MIT",
|
|
46
46
|
"homepage": "https://github.com/chandq/mock-service-cli#readme",
|
|
47
47
|
"dependencies": {
|
|
48
|
+
"body-parser": "^1.20.2",
|
|
48
49
|
"colors": "^1.4.0",
|
|
49
50
|
"deasync": "^0.1.23",
|
|
50
51
|
"express": "^4.17.1",
|