?
API,協調前端與后端開發的連接點。
面臨幾個問題
1. API更新不及時,導致前端開發的接口沒有及時更新而出現各種問題。
2. 文檔描述得不準確
3. 沒有統一的標準。
我們可以使用swagger editor, swagger ui。第一是編輯器,第二個是展示,部署用的。
?
在ubuntu 使用
先下載代碼,然后用npm安裝http-server
git clone https://github.com/swagger-api/swagger-editor.git
sudo? npm install -g http-server
?
http-server –p 2008 swagger-editor
執行上面的命令行在有可能出現錯誤,提示說 env里面沒有node的命令,那是由于ubuntu使用了apt-get安裝了node,為了避免包名沖突,重命名了node。執行下面的命令可以解決這個問題。
sudo ln -s /usr/bin/nodejs /usr/bin/node
?
?
至于swagger-ui,我們創建一個文件夾,比如mkdir node_app
git clone https://github.com/swagger-api/swagger-ui.git 到swagger文件里面
?
?npm init
?npm install express --save
?sudo npm install express --save
?cp -R? ~/swagger/swagger-ui/dist? public
?
上面步驟初始化了npm,然后把一些資源文件復制的到一個新建的目錄public,然后修改index.js
var express = require('express');
var app = express();
app.use('/static', express.static('public'));
app.get('/', function (req, res) {res.send('Hello World!');
});app.listen(3001, function () {console.log('Example app listening on port 3001!');
});
執行這個命令行,就會啟動一個監聽端口3001的服務
node index.js
?
執行命令測試,馬上返回結果
curl localhost:3001 ? ?
Hello World!
?
訪問路徑即可使用網站:
localhost:3001/static/index.html
?
?
?
?
自己搭建了一個gogs的git網上
可以創建一個鏡像,可以創建自己的私有的庫。可以創建web hook
?
?