From 55ed984848cdebd567448f77e9844f6fdcd7c07b Mon Sep 17 00:00:00 2001 From: syuilo Date: Sun, 12 Feb 2017 06:27:47 +0900 Subject: [PATCH] [Server] :v: --- package.json | 1 - src/api/service/github.ts | 15 +++++++++------ 2 files changed, 9 insertions(+), 7 deletions(-) diff --git a/package.json b/package.json index 520eb625c..c1c28d89b 100644 --- a/package.json +++ b/package.json @@ -91,7 +91,6 @@ "file-type": "4.1.0", "fuckadblock": "3.2.1", "git-last-commit": "0.2.0", - "github-webhook-handler": "0.6.0", "glob": "7.1.1", "gm": "1.23.0", "gulp": "3.9.1", diff --git a/src/api/service/github.ts b/src/api/service/github.ts index 4a7a9cb26..00241987a 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;