mtproto-checker 0.4.1 → 0.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (2) hide show
  1. package/check.js +20 -1
  2. package/package.json +1 -1
package/check.js CHANGED
@@ -641,6 +641,12 @@ function createServer({ auth, checkUrl, logger = console.error }) {
641
641
  let statusCode = 500
642
642
 
643
643
  try {
644
+ if (req.url === '/health') {
645
+ statusCode = 200
646
+ jsonResponse(res, statusCode, { status: 'ok', uptime: process.uptime() })
647
+ return
648
+ }
649
+
644
650
  if (!isAuthorized(req, auth)) {
645
651
  statusCode = 401
646
652
  jsonResponse(res, statusCode, { error: 'Unauthorized' }, { 'www-authenticate': realm })
@@ -751,7 +757,20 @@ async function startServer(opts = {}) {
751
757
  })
752
758
 
753
759
  console.error(`[mtproto-checker] ⚡ HTTP server listening on http://localhost:${port}`)
754
- console.error(`[mtproto-checker] POST /check (Basic auth: ${user}:***)`)
760
+ console.error(`[mtproto-checker] GET /health (no auth)`)
761
+ console.error(`[mtproto-checker] POST /check (Basic auth: ${user}:***)`)
762
+
763
+ const shutdown = signal => {
764
+ console.error(`\n[mtproto-checker] ${signal} received, shutting down...`)
765
+ server.close(() => {
766
+ console.error('[mtproto-checker] Server closed.')
767
+ process.exit(0)
768
+ })
769
+ setTimeout(() => { process.exit(1) }, 5000)
770
+ }
771
+ process.on('SIGTERM', () => shutdown('SIGTERM'))
772
+ process.on('SIGINT', () => shutdown('SIGINT'))
773
+
755
774
  return server
756
775
  }
757
776
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mtproto-checker",
3
- "version": "0.4.1",
3
+ "version": "0.4.2",
4
4
  "description": "Check Telegram MTProto proxies via a real TDLib handshake (testProxy), like tdesktop does",
5
5
  "main": "check.js",
6
6
  "exports": {