根据 chat 示例创建 game-server,支持分布式部署、域名访问、数据库连接和基础使用

This commit is contained in:
liangtongchuan
2020-08-15 20:34:31 +08:00
parent e52a829567
commit 8ce0dc040f
36 changed files with 3165 additions and 2 deletions

40
game-server/preload.ts Normal file
View File

@@ -0,0 +1,40 @@
import { Promise } from 'bluebird';
// 支持注解
import 'reflect-metadata';
import { pinus } from 'pinus';
/**
* 替换全局Promise
* 自动解析sourcemap
* 捕获全局错误
*/
export function preload() {
// 使用bluebird输出完整的promise调用链
global.Promise = Promise;
// 开启长堆栈
Promise.config({
// Enable warnings
warnings: true,
// Enable long stack traces
longStackTraces: true,
// Enable cancellation
cancellation: true,
// Enable monitoring
monitoring: true
});
// 自动解析ts的sourcemap
require('source-map-support').install({
handleUncaughtExceptions: false
});
// 捕获普通异常
process.on('uncaughtException', function (err) {
console.error(pinus.app.getServerId(), 'uncaughtException Caught exception: ', err);
});
// 捕获async异常
process.on('unhandledRejection', (reason: any, p) => {
console.error(pinus.app.getServerId(), 'Caught Unhandled Rejection at:', p, 'reason:', reason);
});
}