推薦使用Ubuntu 16.04 LTS,以避免各種不必要的麻煩
一、安裝基礎軟件
Ubuntu
sudo apt-get install git
sudo apt-get install npm
sudo apt-get install redis-server
CentOS
yum install -y git
yum install -y npm
yum install -y redis
二、配置Redis
修改/etc/redis.conf或者/etc/redis/redis.conf
daemon yes
bind 127.0.0.1
port 6379
啟動Redis
Ubuntu
sudo redis-server /etc/redis/redis.conf
CentOS
redis-server /etc/redis.conf
三、安裝apiembed
git clone https://github.com/Mashape/apiembed.git
cd apiembed
sudo npm install
手動修改配置文件package.json
"config": {
"port": 8001
},
四、安裝mockbin
git clone https://github.com/Mashape/mockbin.git
cd mockbin
sudo npm install
手動修改配置文件package.json
"config": {
"port": 80,
"quiet": false,
"redis": "redis://127.0.0.1:6379",
"commitizen": {
"path": "./node_modules/cz-conventional-changelog"
}
},
集成apiembed, 需要修改一下mockbin監(jiān)聽的端口
//filename: src/views/bin/view.jade
// Original code
iframe(src='http://api.apiembed.com/?source=#{req.protocol}://#{req.hostname}/bin/#{req.params.uuid}/sample', frameborder=0, scrolling='no', marginheight=0, marginwidth=0, width='100%', height=350, seamless)
// Solved the problem
iframe(src='http://192.168.1.110:8001/?source=#{req.protocol}://#{req.hostname}/bin/#{req.params.uuid}/sample', frameborder=0, scrolling='no', marginheight=0, marginwidth=0, width='100%', height=350, seamless)
-
mockbin
192.168.1.110:80 -
apiembed
192.168.1.110:8001
至此,mockbin安裝完畢。
五、啟動mockbin
forever是一個簡單的命令式nodejs的守護進程,能夠啟動,停止,重啟App應用。
ref:https://github.com/foreverjs/forever
cd mocbin
forever start server.js
cd apiembed
forever start server.js
forever start -l forever.log -o out.log -e err.log app.js #輸出日志和錯誤