UNPKG

@authup/server-api

Version:

This is a standalone application.

74 lines 2.65 kB
"use strict"; /* * Copyright (c) 2021-2023. * Author Peter Placzek (tada5hi) * For the full copyright and license information, * view the LICENSE file that was distributed with this source code. */ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { if (k2 === undefined) k2 = k; var desc = Object.getOwnPropertyDescriptor(m, k); if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) { desc = { enumerable: true, get: function() { return m[k]; } }; } Object.defineProperty(o, k2, desc); }) : (function(o, m, k, k2) { if (k2 === undefined) k2 = k; o[k2] = m[k]; })); var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { Object.defineProperty(o, "default", { enumerable: true, value: v }); }) : function(o, v) { o["default"] = v; }); var __importStar = (this && this.__importStar) || function (mod) { if (mod && mod.__esModule) return mod; var result = {}; if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); __setModuleDefault(result, mod); return result; }; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.HealthCheckCommand = void 0; const node_http_1 = __importDefault(require("node:http")); const process = __importStar(require("node:process")); const config_1 = require("../../config"); class HealthCheckCommand { constructor() { this.command = 'healthcheck'; this.describe = 'Check if the server is up and running.'; } builder(args) { return args .option('root', { alias: 'r', default: process.cwd(), describe: 'Path to the project root directory.', }); } async handler(args) { const config = await (0, config_1.setupConfig)(); const healthCheck = node_http_1.default.request({ path: '/metrics', host: '0.0.0.0', port: config.get('port'), timeout: 2000, }, (res) => { if (res.statusCode === 200) { process.exit(0); } else { process.exit(1); } }); healthCheck.on('error', () => { process.exit(1); }); healthCheck.end(); } } exports.HealthCheckCommand = HealthCheckCommand; //# sourceMappingURL=healthcheck.js.map