easy-mock 本地部署

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u012878818/article/details/79926117

Easy Mock 是一个可视化,并且能快速生成模拟数据的持久化服务

如果没有内网部署的条件,推荐使用在线服务。只要直接注册就可以使用啦!!!

现在来说说怎么window7系统下 本地部署Easy Mock环境

快速开始

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

MongoDB安装教程:http://www.runoob.com/mongodb/mongodb-window-install.html

Redis安装教程:http://www.runoob.com/redis/redis-install.html


安装

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

配置文件

找到 config/default.json,或者创建一个 config/local.json 文件,将如下需要替换的字段换成自己的配置即可。

不同环境会加载不同的配置文件,在此之前你应该对 node-config 有所了解。

扫描二维码关注公众号,回复: 4960608 查看本文章
{
  "port": 7300,
  "host": "0.0.0.0",
  "pageSize": 30,
  "proxy": false,
  "db": "mongodb://localhost/easy-mock",
  "unsplashClientId": "",
  "redis": {
    "port": 6379,
    "host": "localhost"
  },
  "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
    }
  },
  "fe": {
    "copyright": "",
    "storageNamespace": "easy-mock_",
    "timeout": 25000,
    "publicPath": "/dist/"
  }
}

背景图配置:

登录页的背景图服务目前支持 Unsplash 与 Bing

如果 unsplashClientId 配置留空,默认由 Bing 提供服务。

注意:

  • publicPath 默认是 '/dist/'。如有需要,可以将其替换成自己的 CDN;
  • 关于 fe 的配置,一旦发生改变应该重新执行 build 命令。

启动

$ npm run dev
# 访问 http://127.0.0.1:7300


更多命令

# 前端静态资源构建打包
$ npm run build

# 以生产环境方式启动,需要提前执行 build
$ npm run start

# 单元测试
$ npm run test

# 语法检测
$ npm run lint

服务器部署

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

PM2

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

全局安装 PM2

$ [sudo] npm install pm2 -g

用 PM2 启动

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

$ NODE_ENV=production pm2 start app.js

猜你喜欢

转载自blog.csdn.net/u012878818/article/details/79926117