本地搭建Easy-Mock

本文主要如何本地搭建Easy-Mock

1前置条件

首先需要安装Easy-Mock所需要的环境,自行Google

1
2
3
4

Node.js(v8.x, 不支持 v10.x)
MongoDB(>= v3.4)
Redis(>= v4.0)

2拉去Easy-Mock源码并安装

执行如下代码:

1
2
3

git clone https://github.com/easy-mock/easy-mock.git
cd easy-mock && npm install

3修改配置文件

找到 config/default.json

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52

{
"port": 7300,
"host": "0.0.0.0",
"pageSize": 30,
"proxy": false,
"db": "mongodb://admin:123456@localhost:27017/easymockdb?authSource=admin", // mongodb://用户名:密码@mongodb地址:mongodb端口/项目所用库名?authSource=admin
"unsplashClientId": "",
"redis": {
"keyPrefix": "[Easy Mock]",
"port": 6379, // redis端口号
"host": "localhost", // redis地址
"password": "",
"db": 0
},
"blackList": {
"projects": [], // projectId,例:"5a4495e16ef711102113e500"
"ips": [] // ip,例:"127.0.0.1"
},
"rateLimit": { // https://github.com/koajs/ratelimit
"max": 1000,
"duration": 1000
},
"jwt": {
"expire": "14 days",
"secret": "shared-secret"
},
"upload": {
"types": [".jpg", ".jpeg", ".png", ".gif", ".json", ".yml", ".yaml"],
"size": 5242880,
"dir": "../public/upload",
"expire": {
"types": [".json", ".yml", ".yaml"],
"day": -1
}
},
"ldap": {
"server": "", // 设置 server 代表启用 LDAP 登录。例:"ldap://localhost:389""ldaps://localhost:389"(使用 SSL)
"bindDN": "", // 用户名,例:"cn=admin,dc=example,dc=com"
"password": "",
"filter": {
"base": "", // 查询用户的路径,例:"dc=example,dc=com"
"attributeName": "" // 查询字段,例:"mail"
}
},
"fe": {
"copyright": "",
"storageNamespace": "easy-mock_",
"timeout": 25000,
"publicPath": "/dist/"
}
}

3启动

执行如下代码:

1
2

npm run dev

3部署

执行如下代码:

1
2
3

npm run build
pm2 start app.js // 安装pm2守护进程,pm2使用请参照pm2使用手册

pm2教程:pm2使用手册

扫一扫,请老师喝水