安装mockbin服务

推荐使用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监听的端口

//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 #输出日志和错误

你可能感兴趣的:(安装mockbin服务)