进入app/util文件夹,修改routeUtil.js
var exp = module.exports;
exp.connector = function(session, msg, app, cb){
if(!session){
cb(new Error('fail to route to connector server for session is empty'));
return;
}
if(!session.frontendId){
cb(new Error('fail to find frontend id in session'));
return;
}
cb(null, session.frontendId);
};
打开game-server下的app.js
var pomelo = require('pomelo');
var routeUtil = require('./app/util/routeUtil');
var sync = require('pomelo-sync-plugin');
/**
* Init app for client. 调用pomelo的createApp生成app对象
*/
var app = pomelo.createApp();
//设置app名称为当前项目名称,默认为文件夹名
app.set('name', 'houyuantuan-pomelo');
/**
* 设置app的connector,类型为pomelo init时选择的类型,具体参数
* 包含传输层协议,心跳是否开启,心跳超时时间、心跳间隔时间、超时关闭时间等等
*/
//configure for global
app.configure('production|development', function(){
//route configures
app.route('connector', routeUtil.connector);
app.loadConfig("mysql",app.getBase()+"/../shared/config/mysql.json");
});
//configure database
app.configure('production|development','connector|area|auth',function(){
//初始化dbclient
var dbclient = require('./app/dao/mysql/mysql').init(app);
//dbclient为外部数据库接口,app.get('dbclient')来使用
app.set('dbclient',dbclient);
app.use(sync,{sync:{path:__dirname+'/app/dao/mapping',dbclient: dbclient}});
});
// app configuration
app.configure('production|development', 'connector', function(){
app.set('connectorConfig',
{
connector : pomelo.connectors.hybridconnector,
heartbeat : 3,
useDict : true,
useProtobuf : true
});
});
app.configure('production|development', 'gate', function(){
app.set('connectorConfig',
{
connector : pomelo.connectors.hybridconnector,
useProtobuf : true
});
});
// start app 启动
app.start();
//设置当前程序中未被捕捉而浮到顶层的异常处理
process.on('uncaughtException', function(err) {
console.error(' Caught exception: ' + err.stack);
});