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.
- package/check.js +20 -1
- 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]
|
|
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
|
|