forge-deploy-cli
Version:
Professional CLI for local deployments with automatic subdomain routing, SSL certificates, and infrastructure management
75 lines • 3.27 kB
JavaScript
;
/**
* Standalone Forge API Server
*
* This server runs continuously to provide real-time deployment statistics,
* health checks, and monitoring capabilities for the Forge platform.
*
* Usage:
* node dist/server.js
* pm2 start dist/server.js --name forge-api-server
*/
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const apiServer_1 = require("./services/apiServer");
const chalk_1 = __importDefault(require("chalk"));
const fs_extra_1 = __importDefault(require("fs-extra"));
const path_1 = __importDefault(require("path"));
async function startServer() {
try {
console.log(chalk_1.default.blue.bold('🚀 Starting Forge API Server...'));
console.log();
// Create logs directory if it doesn't exist
const logsDir = path_1.default.join(process.cwd(), 'logs');
await fs_extra_1.default.ensureDir(logsDir);
// Setup graceful shutdown
process.on('SIGINT', gracefulShutdown);
process.on('SIGTERM', gracefulShutdown);
process.on('uncaughtException', (error) => {
console.error(chalk_1.default.red('Uncaught Exception:'), error);
process.exit(1);
});
process.on('unhandledRejection', (reason, promise) => {
console.error(chalk_1.default.red('Unhandled Rejection at:'), promise, 'reason:', reason);
process.exit(1);
});
// Start the API server
const apiServer = new apiServer_1.ForgeAPIServer();
await apiServer.start();
console.log();
console.log(chalk_1.default.green('✅ Forge API Server is running'));
console.log(chalk_1.default.gray('Press Ctrl+C to stop'));
console.log();
console.log(chalk_1.default.cyan('Available endpoints:'));
console.log(chalk_1.default.gray(' GET /health - Server health check'));
console.log(chalk_1.default.gray(' GET /api/deployments - List all deployments'));
console.log(chalk_1.default.gray(' GET /api/deployments/:id - Get deployment details'));
console.log(chalk_1.default.gray(' POST /api/deployments/:id/stop - Stop deployment'));
console.log(chalk_1.default.gray(' GET /api/system - System information'));
console.log();
// Keep the process alive
setInterval(() => {
// Heartbeat log every 5 minutes
console.log(chalk_1.default.gray(`[${new Date().toISOString()}] API Server heartbeat`));
}, 5 * 60 * 1000);
}
catch (error) {
console.error(chalk_1.default.red('Failed to start API server:'), error);
process.exit(1);
}
}
function gracefulShutdown(signal) {
console.log();
console.log(chalk_1.default.yellow(`Received ${signal}. Shutting down gracefully...`));
// Give some time for ongoing requests to complete
setTimeout(() => {
console.log(chalk_1.default.gray('Forge API Server stopped'));
process.exit(0);
}, 2000);
}
// Start the server
startServer();
//# sourceMappingURL=server.js.map