hubotでwebhookを処理する時のデバッグ方法とかあれこれ
概要
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);
});
};
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;
}
}
/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;
}
}
Author And Source
この問題について(hubotでwebhookを処理する時のデバッグ方法とかあれこれ), 我々は、より多くの情報をここで見つけました https://qiita.com/soichiro_nishizawa/items/ff7dd5c177102aa1dacc著者帰属:元の著者の情報は、元のURLに含まれています。著作権は原作者に属する。
Content is automatically searched and collected through network algorithms . If there is a violation . Please contact us . We will adjust (correct author information ,or delete content ) as soon as possible .