pomelo + mysql 学习(四)程序入口app.js

进入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);
});

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值