This is the 10th day of my participation in the August More Text Challenge.

First, the need to build a mock server

  • In the actual development business of the company, whether it is PC terminal, H5 terminal, or the front-end part of the background management system, most of the development mode of front and back end separation is adopted. After reviewing the prototype from the product, the front and back end programmers started their own development. When it comes to the front and back end interfaces, often because the data structures and fields defined by the front and back end programmers are inconsistent, a lot of code needs to be modified, or the data specifications required by the back end are incorrectly transmitted to the front end, repeated debugging, which greatly affects the efficiency of development.
  • Therefore, in the prototype after the review, front and rear end programmer, should not be immediately head start according to the understanding of their development, and should be discussed first pass and return data specification, interface to complete the mock false data, the late debugging, only need to change the address into real interface, a module of alignment self-test time could be from the original one day, Shorten to 2-3 hours, which will greatly improve the development efficiency, so as to enter the test stage earlier, earlier launch, improve team efficiency, solve the team resources, time costs. This is especially true when multiple small teams are working on parallel projects.

Second, use Docker to build the Mocker server

2.1 Prepare a cloud server and install Docker and Docker-compose

# 1.Sudo yum install -y yum-utils sudo yum-config-manager \ --add-repo \https://download.docker.com/linux/centos/docker-ce.repo
 # 2.Docker sudo yum install docker-ce docker-ce cli containerd. IO #3.Docker-compose curl -l"Https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s) - $(uname -m)" -o /usr/local/bin/docker-compose
 # 4.Permission sudo chmod +x /usr/local/bin/docker-compose sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-composeCopy the code

Docker -v Displays that docker is successfully installed

2.2 Use the newly installed Docker to deploy MongoDB

Docker pull mongo: Sudo docker run -d --name some-mongo -p 10050:27017 mongo:4 --zone=public --add-port=10050/ TCP --permanent # reload firewall configuration file firewall-cmd --reloadjsCopy the code

Docker ps see mongoDb already running

We can connect to mongodb locally with Studio 3T. Note that if the connection is not possible, check to see if the cloud server permits the corresponding port.

2.3 Deploying mock Servers using Docker

There are two useful mock services on the market

  1. Doclever doclever. Cn/controller /…
  2. Yapi hellosean1025. Making. IO/yapi/index….

Next we use Doclevel to deploy the mock using docker-compose

# 1.Create vi docker-comemage.yml in /home/doclever/services:
  DOClever:
    image: lw96/doclever
    restart: always
    container_name: "DOClever"
    ports:
    - 20080:10000
    volumes:
    - /srv/doclever/file:/root/DOClever/data/file
    - /srv/doclever/img:/root/DOClever/data/img
    - /srv/doclever/tmp:/root/DOClever/data/tmp
    environment:
    - DB_HOST=mongodb://mongo:27017/DOClever
    - PORT=10000
    links: - mongo:mongo ! [image.png](https://p9-juejin.byteimg.com/tos-cn-i-k3u1fbpfcp/eb601d67eacb4cc8adcfb170f793f908~tplv-k3u1fbpfcp-watermark.image)
  mongo:
    image: mongo:latest
    restart: always
    container_name: "mongodb"
    volumes:
    - /srv/doclever/db:/data/db

# 2.Run the docker-compose up -d # container with the command3.The cloud server permits ports20080
Copy the code

Then the extranet access succeeded

Use Doclever

1. Configure interfaces. The mock server can be directly accessed by Postman or accessed locally from the Intranet

2. Once the backend staff has developed the interface status token, they will not go to the mock server and will go to the following address

# http://localhost:8081 was developed after the completion of the go address node net. Js http:// * * *. * *. 222.218:20080 / mock / 612 a3548977249000c84c170 http://localhost:8081Copy the code

Postman is reporting an error when there is no local interface, proving that the environment is switched back to the formal interface