diff options
| author | syuilo <syuilotan@yahoo.co.jp> | 2017-02-12 06:27:47 +0900 |
|---|---|---|
| committer | syuilo <syuilotan@yahoo.co.jp> | 2017-02-12 06:27:47 +0900 |
| commit | 5149c4cea82f5fb53014565bc756ffd0018dcad0 (patch) | |
| tree | 381811e4b0457e544c898bde1abecf134cbdcda2 /src/api/service | |
| parent | Remove unused code (diff) | |
| download | sharkey-5149c4cea82f5fb53014565bc756ffd0018dcad0.tar.gz sharkey-5149c4cea82f5fb53014565bc756ffd0018dcad0.tar.bz2 sharkey-5149c4cea82f5fb53014565bc756ffd0018dcad0.zip | |
[Server] :v:
Diffstat (limited to 'src/api/service')
| -rw-r--r-- | src/api/service/github.ts | 15 |
1 files changed, 9 insertions, 6 deletions
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; |