ruch
Version:
Revolutionary React TypeScript CLI with hexagonal architecture & AI-powered development assistance. Create maintainable, scalable applications with domain-driven design and integrated AI tooling.
88 lines • 3.49 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.VisualizerServer = void 0;
const express_1 = __importDefault(require("express"));
const path_1 = __importDefault(require("path"));
const cors_1 = __importDefault(require("cors"));
const dependency_analyzer_1 = require("../utils/dependency-analyzer");
const file_operations_1 = require("../utils/file-operations");
class VisualizerServer {
constructor(options) {
this.fileSystem = (0, file_operations_1.createFileSystem)();
this.options = options;
this.app = (0, express_1.default)();
this.setupMiddleware();
this.setupRoutes();
}
setupMiddleware() {
this.app.use((0, cors_1.default)());
this.app.use(express_1.default.json());
// Serve static files from the React app build directory
const buildPath = path_1.default.join(__dirname, 'app', 'build');
this.app.use(express_1.default.static(buildPath));
}
setupRoutes() {
// API route to get graph data
this.app.get('/api/graph-data', async (req, res) => {
try {
this.options.logger.info('Generating graph data...');
const graphData = await (0, dependency_analyzer_1.generateGraphData)(this.fileSystem, this.options.projectRoot);
this.options.logger.info(`Generated graph with ${graphData.nodes.length} domains and ${graphData.edges.length} dependencies`);
res.json(graphData);
}
catch (error) {
this.options.logger.error('Failed to generate graph data:', error);
res.status(500).json({
error: 'Failed to generate graph data',
message: error instanceof Error ? error.message : 'Unknown error'
});
}
});
// Health check endpoint
this.app.get('/api/health', (req, res) => {
res.json({
status: 'ok',
timestamp: new Date().toISOString(),
projectRoot: this.options.projectRoot
});
});
// Serve React app for all other routes
this.app.get('*', (req, res) => {
const buildPath = path_1.default.join(__dirname, 'app', 'build', 'index.html');
res.sendFile(buildPath);
});
}
async start() {
return new Promise((resolve, reject) => {
this.server = this.app.listen(this.options.port, () => {
this.options.logger.info(`Visualizer server started on http://localhost:${this.options.port}`);
resolve();
});
this.server.on('error', (error) => {
this.options.logger.error('Server error:', error);
reject(error);
});
});
}
async stop() {
return new Promise((resolve) => {
if (this.server) {
this.server.close(() => {
this.options.logger.info('Visualizer server stopped');
resolve();
});
}
else {
resolve();
}
});
}
getUrl() {
return `http://localhost:${this.options.port}`;
}
}
exports.VisualizerServer = VisualizerServer;
//# sourceMappingURL=server.js.map