https://github.com/whosydd/mock-server
一个简单的测试服务器
https://github.com/whosydd/mock-server
express mockjs
Last synced: 2 months ago
JSON representation
一个简单的测试服务器
- Host: GitHub
- URL: https://github.com/whosydd/mock-server
- Owner: whosydd
- License: mit
- Created: 2021-11-03T03:43:07.000Z (over 4 years ago)
- Default Branch: main
- Last Pushed: 2021-11-05T10:47:11.000Z (over 4 years ago)
- Last Synced: 2025-06-06T02:16:53.115Z (about 1 year ago)
- Topics: express, mockjs
- Language: JavaScript
- Homepage:
- Size: 81.1 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# mock-server
## 前言
由于只是简单的用来测试接口,所以只封装了常用的`get`、`post`、`patch`、`delete`,如果有其他的需求,可以自行在`src/router/index.js`中进行添加
## 运行
```sh
npm start
```
## 使用
在`src/config/router.json`中配置`path`, `type`, `auth`, `status`, `response`
- path: 请求的路径
- type: 请求类型
- auth: 是否返回 token
- status: 返回状态码,比如在删除数据时,可将其设置为 204,默认 200
- response: 返回数据,可以使用`mockjs`的语法
```json
{
"req1": {
"path": "/get",
"type": "get",
"response": {
"data": {
"msg": "hello world",
"name": "@name"
}
}
},
"req2": {
"path": "/post",
"type": "post",
"auth": true,
"response": {
"data": {
"msg": "hello world",
"name": "@name",
"date": "@date"
}
}
},
"req3": {
"path": "/add",
"type": "post",
"status": 201,
"response": {
"status": 201,
"data": {
"msg": "hello world",
"name": "@name",
"date": "@date"
}
}
},
"req4": {
"path": "/patch",
"type": "patch",
"response": {
"data": {
"msg": "hello world",
"name": "@name",
"date": "@date"
}
}
},
"req5": {
"path": "/delete",
"type": "delete",
"status": 204
}
}
```