2
0
mirror of https://github.com/yagop/node-telegram-bot-api synced 2025-08-28 12:57:38 +00:00

pr/272: Finish on PR

This commit is contained in:
GochoMugo 2017-01-30 13:24:15 +03:00
parent 3263c6c253
commit 9f031a72e5
No known key found for this signature in database
GPG Key ID: 7B6A01CB57AA39E4
3 changed files with 10 additions and 10 deletions

View File

@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
## [Unreleased][Unreleased]
Added:
1. Add health-check endpoint (by @mironov)
* * *

View File

@ -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();

View File

@ -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();