swagger:方便测试人员和客户端开发了解API
1. 第一步搭建官方的swagger ui
1.1 下载
git clone https://github.com/swagger-api/swagger-ui.git
1.2 创建一个另外的文件夹--用来发布
mkdir swagger
1.3 在发布的文件夹下面安装express
cd swagger
npm init
npm install express --save
1.4 创建目录public,并将刚才clone下来的Swagger UI中dist目录下的所有文件全部复制到public目录下面
cp -r ../swagger-ui/dist/ ./public
1.5 创建express主程序
var express = require('express');
var app = express();
// 接口显示页面
app.use('/static', express.static('public'));
app.listen(8005, function () {
console.log('app listening on port 8005!');
});
1.6 启动服务
node swagger.js
# 用pm2启动
pm2 start swagger.js
1.8 访问
http://192.168.185.231:8005/static/index.html
2. 替换官方的API
2.1 安装swagger-edit
git clone https://github.com/swagger-api/swagger-editor.git
npm init
2.2 启动swagger-edit
# 直接退回swagger-edit的父目录,然后启动便可
miao@miao-VirtualBox:~/workspace$ ls
sod swagger swagger-editor swagger-ui
miao@miao-VirtualBox:~/workspace$ http-server swagger-editor
Starting up http-server, serving swagger-editor
Available on:
http://127.0.0.1:8080
http://192.168.185.231:8080
Hit CTRL-C to stop the server
2.3 静默启动
nohup http-server swagger-editor >> /home/miao/workspace/swagger-editor.log 2>&1 &