在开始之前,假设你已经成功安装了 Node.js(v8.x,
不支持 v10.x)& MongoDB(>= v3.4)& Redis(>= v4.0)。
$ git clone https://github.com/easy-mock/easy-mock.git $ cd easy-mock && npm install --unsafe-perm
找到 config/default.json,或者创建一个 config/local.json 文件,将如下需要替换的字段换成自己的配置即可。
不同环境会加载不同的配置文件,在此之前你应该对 node-config 有所了解。
{ "port": 7300, "host": "0.0.0.0", "pageSize": 30, "proxy": false, "db": "mongodb://localhost/easy-mock", "unsplashClientId": "", "redis": { "keyPrefix": "[Easy Mock]", "port": 6379, "host": "localhost", "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/" } }
背景图配置:
登录页的背景图服务目前支持 Unsplash 与 Bing。
如果 unsplashClientId
配置留空,默认由 Bing 提供服务。
注意:
publicPath
默认是 ‘/dist/‘
。如有需要,可以将其替换成自己的 CDN;fe
的配置,一旦发生改变应该重新执行 build 命令。2、构建
# 前端静态资源构建打包
$ npm run build
# 以生产环境方式启动,需要提前执行 build $ npm run start # 单元测试 $ npm run test # 语法检测 $ npm run lint
$ npm run start # 访问 http://127.0.0.1:7300注意
在此之前请先配置好配置文件。
当在内网服务器部署时,推荐使用 PM2 来守护你的应用进程。
$ [sudo] npm install pm2 -g
在此之前,你应该已经完成了 build。
$ NODE_ENV=production pm2 start app.js
原文:https://www.cnblogs.com/DotSDot/p/13246996.html