Background:

Easy-mock is a popular mock data site, but as more and more users use it, the easy-Mock interface is sometimes slow to respond (also due to the local network environment), and the interface is unstable and sometimes fails.

Requirements:

The company has a dedicated machine to build Intranet servers for developers to use, so we want to deploy easy-Mock locally, so that the interface stability and response speed can be guaranteed, and it is also very helpful for team development.

Implementation:

Take a look at the official introduction to easy-Mock native deployment at github.com/easy-mock/e… The steps introduced on the official website are roughly divided into the following steps:

  • Install node (>=v8.9) & MongoDB (>=v3.4) & Redis (>=v4.0)
  • Install easy-mock and change the configuration file
  • Start the Easy-mock test to see if the project starts properly, Ctrl + C if it does
  • Start MongoDB and Redis
  • NPM run build, then start app.js with PM2

Step 1 – Install Node

The recommended use of NVM version management and NRM download source management is not covered here.

Step 2 – Install MongoDB

  • Win MongoDB installation tutorial
  • MongoDB configuration environment variables are not clear, I rewrite here:
MONGO_HOME = C:\Program Files\MongoDB\Server\3.4\bin
Path = %MONGO_HOME%
Copy the code
  • The Robo 3T visualization tool is recommended

Step 3 – Install Redis

You can download the installation package directly from redis. IO /download.

To open acmdWindow, enter switch to redis installation directory:
redis-server.exe redis.windows.conf
Copy the code
Add Redis to Windows services
redis-server.exe --service-install redis.windows.conf --loglevel verbose
Copy the code
Start the service under CMD
redis-server --service-start
Copy the code
The Redis command is used:
  • Uninstall service:redis-server --service-uninstall
  • Start service:redis-server --service-start
  • Stop service:redis-server --service-stop

Step 4 – Install easy-mock

Git clone: NPM install, NPM run dev: config/default.json: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev: NPM run dev Easy-mock automatically uses MongoDB and Redis and requires no further action. Easy-mock will start under 7300 by default. Open IP +port of the server to check whether easy-Mock starts normally.

{
  "port": 7300.// The port on which the easyMock project is launched
  "host": "localhost".// set localhost to 0.0.0.0
  "pageSize": 30."proxy": false."db": "mongodb://localhost/easy-mock".// You don't need to create a new database yourself, just create a new interface on the launched EasyMock
  "unsplashClientId": ""."redis": {
    "port": 6379./ / redis port
    "host": "localhost"
  },
  "blackList": {
    "projects": [].// projectId, for example: "5A4495E16EF711102113E500"
    "ips": [] // IP, for example: "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/"}}Copy the code

Step 5 – Deployment phase

  • Install pM2 globally
npm install pm2 -g 
Copy the code
  • Compile easy-mock files
npm run build
Copy the code
  • Start the
cross-env NODE_ENV=production pm2 start app.js --name easymock
Copy the code
  • Viewing All Services
pm2 list
Copy the code
  • access
localhost:7300
Copy the code
  • stop
pm2 stop easymock
Copy the code
  • Kill the process
pm2 kill easymock
Copy the code

Step 6 – In Windows, configure the PM2 service to automatically start upon startup

  • Install and configure pm2-Windows-service
npm i -g pm2-windows-service
Copy the code
  • Add. Pm2 system environment variables
PM2_HOME=C:\Users\zhtop.pm2(path defaults to.pm2 under current user)Copy the code
  • Open a new CMD command line window as an administrator and run the following command to install the service
pm2-service-install
Copy the code
  • promptPerform environment setup ?nIf the PM2 service is installed and started, the PM2 service is available[win + r][ services.msc]The service name is PM2