LoginSignup
1
2

More than 5 years have passed since last update.

hubotでwebhookを処理する時のデバッグ方法とかあれこれ

Posted at

概要

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;
  }
}

参考
http://wiki.nginx.org/IfIsEvil

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2