From 5149c4cea82f5fb53014565bc756ffd0018dcad0 Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Feb 2017 06:27:47 +0900 Subject: [Server] :v: --- src/api/service/github.ts | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/api/service/github.ts') diff --git a/src/api/service/github.ts b/src/api/service/github.ts index 4a7a9cb26f..00241987ab 100644 --- a/src/api/service/github.ts +++ b/src/api/service/github.ts @@ -1,5 +1,5 @@ +import * as EventEmitter from 'events'; import * as express from 'express'; -const createHandler = require('github-webhook-handler'); import User from '../models/user'; import config from '../../conf'; @@ -17,12 +17,15 @@ module.exports = async (app: express.Application) => { const post = text => require('../endpoints/posts/create')({ text }, bot); - const handler = createHandler({ - path: '/hooks/github', - secret: config.github_bot.hook_secret - }); + const handler = new EventEmitter(); - app.post('/hooks/github', handler); + app.post('/hooks/github', (req, res, next) => { + if (req.headers['x-hub-signature'] == config.github_bot.hook_secret) { + handler.emit(req.headers['x-github-event'], req.body); + } else { + res.sendStatus(400); + } + }); handler.on('push', event => { const ref = event.payload.ref; -- cgit v1.2.3-freya