This is the second day of my participation in Gwen Challenge

preface

The traditional way when finish the backend development interface, and then through inform front to docking port, in the form of document and interface has to modify or update, just need to cover in the form of document before that, and not conducive to update and maintain, then we need a backend interface management, standard interface by the background document, but also conducive to change back, Below, I use YApi to build the interface management background of my interface team, because YApi has powerful functions and can realize Intranet deployment, which is efficient and easy to use.

First, environmental requirements

  • Linux system
  • Node. Js (+ 7.6)
  • Directing (+ 2.6)
  • pm2

Install Node.js

YApi depends on Node V7.6.0 or later. If Node version is earlier than 7.6.0, upgrade Node. If the project depends on different versions of Node.js, you can use the Node.js version management tool NVM to switch the required version of the current project.

/ / select Node. Js installed version of the $curl - sL https://deb.nodesource.com/setup_12.x | sudo bash - E - / / installation Node. Js $yum install - y nodejsCopy the code

Mongodb installation

(1) Configure the mongodb yum source file

The purpose of the configuration source file is to find and install dependent software from the defined path.

Repo $touch /etc/yum.repos. D /mongodb-org.repoCopy the code

(2) Edit the mongodb-org.repo file

$ vim /etc/yum.repos.d/mongodb-org.repo
Copy the code

(3) Add the following content to the mongodb-org.repo file

[mongodb-org] name=MongoDB Repository baseurl=http://mirrors.aliyun.com/mongodb/yum/redhat/7Server/mongodb-org/4.4/x86_64/ gpgcheck = 0 enabled = 1Copy the code

(4) Install mongodb

$ yum install -y mongodb-org
Copy the code

(5) Start mongodb

$service mongod start or systemctl start mongodCopy the code

(6) Check the startup status and check whether the startup is successful

$service mongod status or systemctl status mongodCopy the code

4. Configure YApi

(1) YApi installed and started

Here I use the recommended method for deployment, executing yAPI Server to start the visual deployer. Go to http://0.0.0.0:9000 in your browser and replace 0.0.0.0 with the domain name or IP address on your server.

$ npm install -g yapi-cli --registry https://registry.npm.taobao.org
$ yapi server
Copy the code

(2) Platform deployment

The following page is the way of visual deployment. Enter the corresponding configuration and click Start deployment to complete the deployment of the entire website.

(3) Start the service

After the deployment is complete, run the node /verdors/server/app.js command as prompted to start the server. Open the specified URL in the browser, click Login, enter the administrator email you just set, and log in to the system with the default password (YMfe.org) (the default password can be changed in the personal center).

// Start the service $node /verdors/server/app.jsCopy the code

5. Use the PM2 daemon process

After YApi service is started, if you exit the command terminal or press “CTRL + C” command, the YApi process will be terminated immediately and the YApi service will be inaccessible. In this case, we need to daemon the process. We can use pm2 or forever to daemon the process.

Pm2 $NPM install pm2 -g // CD /verdors/server/ $pm2 start app.jsCopy the code

Six, the use of

Go to http://0.0.0.0:3000 in your browser and replace 0.0.0.0 with the domain name or IP on your server. This is the official usage document, which contains powerful features waiting for you to discover.