UNPKG

commit-guardian

Version:

Interactive CLI tool with browser-based GitHub-style diff viewer for reviewing and approving git changes before commit. Features React-based UI, approval workflow, line comments, and safe commit protection.

54 lines (53 loc) 2.07 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.startServer = startServer; const express_1 = __importDefault(require("express")); const path_1 = __importDefault(require("path")); const cors_1 = __importDefault(require("cors")); const diff_1 = __importDefault(require("./routes/diff")); const approve_1 = __importDefault(require("./routes/approve")); const reject_1 = __importDefault(require("./routes/reject")); const app = (0, express_1.default)(); // Middleware app.use(express_1.default.json()); app.use((0, cors_1.default)()); // API routes app.use('/api', diff_1.default); app.use('/api', approve_1.default); app.use('/api', reject_1.default); // Serve static files (both development and production) const clientDistPath = path_1.default.join(__dirname, '../client'); app.use(express_1.default.static(clientDistPath)); // Handle client-side routing (except API routes) app.get('/', (req, res) => { res.sendFile(path_1.default.join(clientDistPath, 'index.html')); }); // Fallback for other non-API routes app.get(/^(?!\/api).*/, (req, res) => { res.sendFile(path_1.default.join(clientDistPath, 'index.html')); }); exports.default = app; function startServer(options) { return new Promise((resolve, reject) => { const server = app.listen(options.port, () => { const url = `http://localhost:${options.port}`; console.log(`🚀 Review server started at ${url}`); global.commitGuardianOptions = options; resolve({ server, url }); }).on('error', (err) => { if (err.code === 'EADDRINUSE') { // Try next port const nextPort = options.port + 1; startServer({ ...options, port: nextPort }) .then(resolve) .catch(reject); } else { reject(err); } }); }); }