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:
parent
3263c6c253
commit
9f031a72e5
@ -5,6 +5,9 @@ This project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
## [Unreleased][Unreleased]
|
||||
|
||||
Added:
|
||||
|
||||
1. Add health-check endpoint (by @mironov)
|
||||
|
||||
|
||||
* * *
|
||||
|
@ -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();
|
||||
|
@ -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();
|
||||
|
Loading…
x
Reference in New Issue
Block a user