概要
hubotもnodejsもcoffeeも全く知見ない状態からやり始めて苦労したので備忘録としてメモ
webhook拾う部分とそのデバッグについて書いといた
hubotのアダプタをshellにして見るか、↓の設定しておいてforever
で動かした後にtail -f
しとけばデバッグ楽ちんだった
hubotのスクリプト
hubot/scripts/sample.js
let fs = require('fs');
let Log = require('log');
let stream = fs.createWriteStream('my.log');
let logger = new Log(process.env.HUBOT_LOG_LEVEL || 'info', stream);
module.exports = function (robot) {
robot.logger = logger;
robot.router.post(/webhook/, function (req, res){
let data = req.body;
robot.logger.info(data);
});
};
my.logはhubotディレクトリ下に吐かれるよ
NginxのリバースプロキシでPOSTを渡す設定
/etc/nginx/conf.d/hubot.conf
server {
listen 80 default;
server_name webhook.sample.com;
if ($request_method = POST) {
return 418;
}
error_page 418 @POST;
location ~ @POST {
proxy_read_timeout 300;
proxy_connect_timeout 300;
proxy_redirect off;
proxy_set_header X-Forwarded-Proto $scheme;
proxy_set_header Host $http_host;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
proxy_set_header Host $host;
proxy_pass http://localhost:8080;
}
}