GitHub 的网络钩子(webhook)功能,可以很方便的实现自动化部署。本文记录了使用 Node.js 的开发部署过程,当项目的 master 分支被推时,将在服务器进行自动部署,完整代码见 GitHub
添加网络钩子
-
在 GitHub 的相应项目首页,点击右上角菜单
Setting
, 点击左侧菜单Webhooks
,点击右上角按钮Add webhook
-
设置
Payload URL
为接收事件的地址,Content type
建议选择applicaiton/json
,Secret
可选填任意字符串,Which events would you like to trigger this webhook?
设为Just the push event.
,勾选Active
,点击下方的Add webhook
按钮
开发处理请求
接收请求
使用 Node.js 建立一个 http 服务器,接收 POST 请求并处理其提交数据
const { createServer } = require(&