Create a new router for the robot

This commit is contained in:
Brandon Keepers 2017-08-01 14:05:34 -05:00
parent 74e59724b8
commit d17d9b717b
No known key found for this signature in database
GPG Key ID: F9533396D5FACBF6
3 changed files with 18 additions and 2 deletions

View File

@ -31,7 +31,10 @@ module.exports = (options = {}) => {
debug: process.env.LOG_LEVEL === 'trace'
});
const server = createServer(webhook);
const robot = createRobot({app, cache, logger, router: server, catchErrors: true});
const robot = createRobot({app, cache, logger, catchErrors: true});
// Connect the router from the robot to the server
server.use(robot.router);
// Forward webhooks to robot
webhook.on('*', event => {

View File

@ -1,6 +1,7 @@
const {EventEmitter} = require('promise-events');
const GitHubApi = require('github');
const Bottleneck = require('bottleneck');
const express = require('express');
const Context = require('./context');
/**
@ -13,7 +14,7 @@ class Robot {
this.events = new EventEmitter();
this.app = app;
this.cache = cache;
this.router = router;
this.router = router || new express.Router();
this.log = wrapLogger(logger);
this.catchErrors = catchErrors;
}

View File

@ -23,4 +23,16 @@ describe('Probot', () => {
expect(probot.robot.receive).toHaveBeenCalledWith(event);
});
});
describe('server', () => {
const request = require('supertest');
it('adds routes from plugins', () => {
probot.load(robot => {
robot.router.get('/foo', (req, res) => res.end('bar'));
});
return request(probot.server).get('/foo').expect(200, 'bar');
});
});
});