首页 > 其他 > 详细

easy-mock安装

时间:2020-07-05 18:49:24      阅读:54      评论:0      收藏:0      [点我收藏+]

在开始之前,假设你已经成功安装了 Node.js(v8.x, 不支持 v10.x)& MongoDB(>= v3.4)& Redis(>= v4.0)。

1、安装

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

注意:
--unsafe-perm的意思为跨过权限问题进行安装,若不加该词安装过程中可能会一直显示nodejs gyp WARN EACCES user “root” does not have permission to access the dev dir***导致安装失败。

配置文件

找到 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

3、启动

$ npm run start
# 访问 http://127.0.0.1:7300注意

注意:防火墙打开7300端口。

服务器部署

在此之前请先配置好配置文件。

PM2

当在内网服务器部署时,推荐使用 PM2 来守护你的应用进程。

全局安装 PM2

$ [sudo] npm install pm2 -g

用 PM2 启动

在此之前,你应该已经完成了 build。

$ NODE_ENV=production pm2 start app.js

easy-mock安装

原文:https://www.cnblogs.com/DotSDot/p/13246996.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!