forked from mirrors/probot
Create a new router for the robot
This commit is contained in:
parent
74e59724b8
commit
d17d9b717b
5
index.js
5
index.js
|
@ -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 => {
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
|
|
|
@ -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');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue