mira-app-server
Version:
Mira Server - standalone server application using mira-app-core
86 lines • 3.21 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.MiraServer = void 0;
const mira_app_core_1 = require("mira-app-core");
const HttpServer_1 = require("./HttpServer");
const WebSocketServer_1 = require("./WebSocketServer");
class MiraServer {
constructor(config = {}) {
this.config = {
httpPort: 8081,
wsPort: 8081,
enableHttp: true,
enableWebSocket: true,
...config
};
console.log('🚀 Initializing Mira Server...');
console.log('📋 Configuration:', this.config);
// 初始化后端 - 只传递MiraBackend认识的属性
this.backend = new mira_app_core_1.MiraBackend({
dataPath: this.config.dataPath,
wsPort: this.config.wsPort,
autoLoad: true,
autoStart: true
});
}
async start() {
try {
console.log('🔄 Starting Mira Server components...');
// 启动HTTP服务器
if (this.config.enableHttp) {
this.httpServer = new HttpServer_1.MiraHttpServer(this.backend, this.config.dataPath);
await this.httpServer.initialize();
await this.httpServer.start(this.config.httpPort);
}
// 启动WebSocket服务器(复用HTTP服务器)
if (this.config.enableWebSocket && this.httpServer) {
this.wsServer = new WebSocketServer_1.WebSocketServer(this.httpServer.getHttpServer(), this.backend);
console.log(`🔌 WebSocket Server initialized on port ${this.config.httpPort}`);
}
console.log('✅ Mira Server started successfully!');
this.printServerInfo();
}
catch (error) {
console.error('❌ Failed to start Mira Server:', error);
throw error;
}
}
async stop() {
console.log('🔄 Stopping Mira Server...');
if (this.httpServer) {
await this.httpServer.stop();
}
console.log('✅ Mira Server stopped successfully');
}
printServerInfo() {
console.log('\n' + '='.repeat(60));
console.log('🎉 MIRA SERVER RUNNING');
console.log('='.repeat(60));
if (this.config.enableHttp) {
console.log(`📍 HTTP API: http://localhost:${this.config.httpPort}/api`);
console.log(`🏥 Health Check: http://localhost:${this.config.httpPort}/health`);
}
if (this.config.enableWebSocket) {
console.log(`🔌 WebSocket: ws://localhost:${this.config.httpPort}`);
}
console.log(`📂 Data Path: ${this.config.dataPath || 'default'}`);
console.log('='.repeat(60) + '\n');
}
getBackend() {
return this.backend;
}
getHttpServer() {
return this.httpServer;
}
getWebSocketServer() {
return this.wsServer;
}
// 静态方法用于快速启动
static async createAndStart(config = {}) {
const server = new MiraServer(config);
await server.start();
return server;
}
}
exports.MiraServer = MiraServer;
//# sourceMappingURL=MiraServer.js.map