Small knowledge, big challenge! This article is participating in the creation activity of “Essential Tips for Programmers”.

Easy Mock is a persistent service that visualizes and quickly generates Mock data. Forget these practical but troublesome mocks.

Common mocks:

  • Write simulation data directly in code
  • Use JavaScript to intercept requests
  • Use Charles, Fiddler, and other proxy tools to intercept requests

EasyMock platform can be used to define interfaces and mock interface data more quickly and reduce the workload of front-end and back-end docking. Since easy-Mock online services are often unstable and prone to data loss, local deployment is as follows:

Install Node (>=v8.9, but not v10.x) & MongoDB (>=v3.4) & Redis (>=v4.0)

1. Nodejs is deployed locally

[root @ localhost /] $CD/opt root @ localhost/opt $wget HTTP: / / http://nodejs.org/dist/v11.5.0/node-v11.5.0-linux-armv7l.tar.xz [root@localhost /opt]$tar xf node-v11.5.0-linux-.armv7.tar -c /usr/local/nodejs [root@localhost /opt]$CD /usr/local/ Root @ localhost/local $mv node - v5.10.1 - Linux - x64 / nodejs root @ localhost/local $ln -s/usr/local/nodejs/bin/node /usr/bin # create soft link Can be run directly root @ localhost/local $ln -s/usr/local/nodejs/bin/NPM/usr/bin/root @ localhost/local] $node - v # to check the versionCopy the code

Tips: This ln operation. Environment variables can also be configured: vim /etc/profile adds variable configuration, then source /etc/profile takes effect immediately

2. Deploy Mongodb locally

[root@localhost /]$ cd /opt [root@localhost opt]$ wget http://downloads.mongodb.org/linux/mongodb-linux-x86_64-rhel70-3.2.10.tgz [root @ localhost opt] $tar ZXF Mongodb -linux-x86_64-rhel70-3.2.10.tgz [root@localhost opt]$mv mongodb-linux-x86_64-rhel70-3.2.10 /data/mongodb [root@localhost opt]$ mkdir -p /data/mongodb/db /data/logs/mongodb [root@localhost opt]$ vim /etc/mongod.conf # configure mongodb port, log path, Dbpath =/data/mongodb/db port=10012 # default 27017 bind_ip = 0.0.0.0 # default 127.0.0.1 logpath=/data/mongodb/logs//mongod.log fork = true [root@localhost opt]$ cd /data/mongodb/bin [root@localhost bin]$ /mongod -f /etc/mongod. Conf & # --dbpath= The default path is/data/db need to manually create - port specified port [root @ localhost bin] $ps - aux | grep mongod # check the startup process [root @ localhost bin] $. / mongo 27017 >use admin; 27017 >use admin; >db.createUser({user:"root",pwd:"yourpasswd",roles:["root"]}); >db.auth("root","yourpasswd");Copy the code

3. Redis is deployed locally

[root @ localhost /] $CD/opt root @ localhost/opt $wget HTTP: / / http://download.redis.io/releases/redis-2.8.0.tar.gz [root@localhost /opt]$tar ZXF redis-2.8.0.tar.gz [root@localhost /opt]$mv redis2.8 /data/redis [root@localhost /opt]$ yum install gcc cpp binutils glibc glibc-kernheaders glibc-common glibc-devel tcl [root@localhost /redis]$ make && make test [root@localhost /redis]$ cd src [root@localhost /src]$ make install [root@localhost /src]$ ./redis-server & Root @ localhost/SRC $. / redis server/data/redis/etc/redis. Conf root @ localhost/opt $service redisd on/off switch on the rev/closed [root@localhost /opt]$ service redisd stop /start [root@localhost /opt]$ redis-server -h localhost -p 10015 -a yourAuthpasswdCopy the code

4. Clone the Easy-mock locally and deploy it

[root@localhost /opt]$ git clone https://github.com/easy-mock/easy-mock.git [root@localhost /opt]$ cd easy-mock && npm Install [root@localhost /easy-mock]$vim config/default.json {"port": 7300, #easy-mock "host": "0.0.0.0", "pageSize": 30, "proxy": false, "db": "mongodb://localhost/easy-mock", # keep the default Settings "unsplashClientId": "", "redis": {"keyPrefix": "[Easy Mock]", "port": 6016, #redis service port" host": "localhost", "password": "Hcpdev0327 ", #redis -- auth authentication password, no error "db": 8}, [root@localhost /easy-mock]$NPM run devCopy the code

When nohup is used, the startup command is not executed in the background, and will exit. Finally give up and use the node app.js command

Tips: When deployed on an Intranet server, PM2 is recommended to guard your application processes.

[root@localhost /easy-mock]$ npm install pm2 -g
[root@localhost /easy-mock]$ npm run build
[root@localhost /easy-mock]$ NODE_ENV=production pm2 start app.js
Copy the code

5. At this point, the entire Easy-mock localization is deployed in the Linux environment, and you can log in by accessing IP +port. If an account does not exist, the system will automatically create one.

6. Summary

Finally, why mock, advocating the separation of front and back end development, must be to improve development efficiency, save more time to test, ensure the project release time.