var pomelo = require('pomelo'); const dispatcher = require('./app/util/dispatcher'); const ChatService = require('./app/services/chatService'); /** * Init app for client. */ var app = pomelo.createApp(); app.set('name', 'r2'); app.loadConfig('mysql', app.getBase() + '/config/mysql.json'); app.loadConfig('redis', app.getBase() + '/config/redis.json'); var chatRoute = function(session, msg, app, cb) { var chatServers = app.getServersByType('chat'); if(!chatServers || chatServers.length === 0) { cb(new Error('can not find chat servers.')); return; } var res = dispatcher.dispatch(session.get('uid'), chatServers); cb(null, res.id); }; // app configuration app.configure('production|development', function(){ app.set('connectorConfig', { connector : pomelo.connectors.hybridconnector, heartbeat : 3, useDict : true, useProtobuf : true }); app.route('chat', chatRoute) }); app.configure('production|development', 'chat', function(){ app.set('chatService', new ChatService(app)); }); app.configure('production|development', 'master', function() { app.enable('systemMonitor'); }); // start app app.start(); process.on('uncaughtException', function (err) { console.error(' Caught exception: ' + err.stack); });