[TOC]

What is YApi

YApi aims to provide more elegant interface management services for developers, products and testers. It’s easy to create, publish, and maintain apis: mock data, interface documentation, and interface testing yAPI

At present, there are several more widely used

The name of the Private deployment Whether the charge Technology stack
eolinker support is The unknown
rap2 support no nodejs mysql react
yapi support no nodejs MongoDB react

Swagger, postMan, easyMock…

Yapi is now easy to use, beautiful, functional, free and open source,

Experience: 20 technical team members, 2 years, more than 30 projects ravage now stable

🌈 fart end, body:

1 installation mangodb

Uncheck Compass (Visualization tool)

MongoDB does not require login by default, so skip this step if you do not

Create two users, one administrator and one ordinary user of the yAPI table. (you must create the yAPI table and the corresponding user, otherwise the database verification will fail.)

The MongoDB installation directory is usually C:\Program Files\MongoDB\Server\ version number \bin

The command line locates this directory and directly runs.\mongo.exe to enter command mode and execute the following code

> use admin
> db.createUser({user: "root".pwd: "root",roles:[{ role: "userAdminAnyDatabase".db: "admin"}]})
> use yapi
> db.createUser( {user: "yapi".pwd: "123456",roles: [ { role: "readWrite".db: "yapi"}]})Copy the code

Complete interaction process

> use admin
switched to db admin
> db.createUser({user: "root".pwd: "root",roles:[{ role: "userAdminAnyDatabase".db: "admin"}]})
Successfully added user: {
        "user" : "root"."roles": [{"role" : "userAdminAnyDatabase"."db" : "admin"
                }
        ]
}
> use yapi
switched to db yapi
> db.createUser( {user: "yapi".pwd: "123456",roles: [ { role: "readWrite".db: "yapi" } ]})
Successfully added user: {
        "user" : "yapi"."roles": [{"role" : "readWrite"."db" : "yapi"}}] >Copy the code

Enable MongoDB authentication

Find mongod.cfg in the mongoDB installation directory

Enable security (different versions may have different Settings, please search by yourself)

security:
  authorization: enabled
Copy the code

Restart MongoDB to proceed to the next step

2. Install YAPI

Set the image source 😄

npm config set registry https://registry.npm.taobao.org
Copy the code

Step 1: Visualize your organization

Execute yAPI Server to start the visual deployer, enter the appropriate configuration and click Start Deployment to complete the deployment of the entire site. After the deployment is complete, run the node/{website path /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).

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

Method 2: Cli deployment

If github compressed files cannot be downloaded or need to be deployed on special servers, try this method

mkdir yapi
cd yapi
git cloneVendors / / https://github.com/YMFE/yapi.git or download the zip package into vendors directory (cloneThe whole repository is about 140+ M and can be gitclone- the depth = 1 https://github.com/YMFE/yapi.git vendors ` command, About 10+ M) cp vendors/config_example.json./config.json // Modify the Settings after replication is completecdvendors npm install --production --registry https://registry.npm.taobao.org npm run install-server // After starting the server, please visit 127.0.0.1:{config.json configured port}. The first run will have a compilation process. Please be patientCopy the code

3. Visually deploy YAPI

Database authentication if the above MongoDB create user open, do not select it ignore

4. The installation is complete

Open the corresponding directory based on the deployment path selected by the deployment procedure

Your deployment directory \vendors\ ServerCopy the code

Command line to access the directory node app.js

D:\yapi\vendors\server>node app.js
log: -------------------------------------swaggerSyncUtils constructor----------
-------------------------------------
log: The service has started, please open the following link to visit: http://127.0.0.1:5500/log: mongodb load success...
Copy the code

At this point you can have fun;

However, every time the server goes down, you need to manually use Node app.js

The old rules refer to the next step

5. Register as a service

In order to maintain service, the server can still run after restarting,

Here amway a WIN environment to register the command line as a service artifact WinSW

Currently version 3.0 is alpha, so I chose V2.10.3

Download the appropriate version based on the server environment (I select here. WinSW.NET 2.0. Exe)

NET2 NET4 NET461 corresponds to the. Net framework2.0/4.0/4.61

CoreX is estimated to correspond to.net Core

Configuration instructions link to www.jianshu.com/p/1ee1a8526…

After downloading the exe program, create a new directory and put the EXE in it. In the same directory, create an XML file with the same name as exe for configuration

winsw.exe install
Copy the code

The configuration is as follows (modify according to the path)

<service>   
    <id>yapi</id>
    <name>yapi-service</name>  
    <description>Yapi interface service, based on Winsw</description>  
    <executable>C:\Program Files (x86)\nodejs\node.exe</executable>
    <logmode>rotate</logmode>	
    <argument>D:\yapi\vendors\server\app.js</argument>
    <argument>--log</argument>
    <argument>yapi start log</argument>	
    <stoptimeout>30sec</stoptimeout>
    <depend>mongodb</depend>
</service>

Copy the code

Open the service and find the service check dependency corresponding to yAPI

Start the service Enjoy! 😄