Skip to content

Commit

Permalink
pr/272: Finish on PR
Browse files Browse the repository at this point in the history
  • Loading branch information
passion-27 committed Jan 30, 2017
1 parent cbac315 commit 600b063
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 10 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased][Unreleased]

Added:

1. Add health-check endpoint (by @mironov)


* * *
Expand Down
15 changes: 6 additions & 9 deletions src/telegramWebHook.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,23 +136,20 @@ class TelegramBotWebHook {
debug('WebHook request headers: %j', req.headers);

if (this._regex.test(req.url)) {
if (req.method === 'POST') {
req
.pipe(bl(this._parseBody))
.on('finish', () => res.end('OK'));
} else {
// Authorized but not a POST
if (req.method !== 'POST') {
debug('WebHook request isn\'t a POST');
res.statusCode = 418; // I'm a teabot!
res.end();
} else {
req
.pipe(bl(this._parseBody))
.on('finish', () => res.end('OK'));
}
} else if (this._healthRegex.test(req.url)) {
// If this is a health check
debug('WebHook health check passed');
res.statusCode = 200;
res.end('OK');
} else if (!this._regex.test(req.url)) {
// If there isn't token on URL
} else {
debug('WebHook request unauthorized');
res.statusCode = 401;
res.end();
Expand Down
2 changes: 1 addition & 1 deletion test/telegram.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ describe('TelegramBot', function telegramSuite() {
});

describe('WebHook', function webHookSuite() {
it('returns OK for healthz endpoint', function test(done) {
it('returns 200 OK for health endpoint', function test(done) {
utils.sendWebHookRequest(webHookPort2, '/healthz', { json: false }).then(resp => {
assert.equal(resp, 'OK');
return done();
Expand Down

0 comments on commit 600b063

Please sign in to comment.