Skip to content

Commit 5588f96

Browse files
committed
Yaml config
1 parent 413b784 commit 5588f96

16 files changed

+303
-190
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ npm-debug.log*
1010
yarn-debug.log*
1111
yarn-error.log*
1212
lerna-debug.log*
13+
config.yaml
1314

1415
matches/*
1516
# OS

bun.lockb

9.16 KB
Binary file not shown.

package.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,9 @@
4747
"cache-manager-redis-yet": "^5.1.4",
4848
"cheerio": "^1.0.0",
4949
"dotenv": "^16.4.5",
50+
"fluent-logger": "^3.4.1",
5051
"ioredis": "^5.4.1",
52+
"js-yaml": "^4.1.0",
5153
"pg": "^8.13.1",
5254
"pg-hstore": "^2.3.4",
5355
"reflect-metadata": "^0.2.2",
@@ -57,7 +59,8 @@
5759
"sequelize": "^6.37.5",
5860
"sqlite3": "^5.1.7",
5961
"swagger-ui-express": "^5.0.1",
60-
"typeorm": "^0.3.20"
62+
"typeorm": "^0.3.20",
63+
"winston": "^3.17.0"
6164
},
6265
"devDependencies": {
6366
"@nestjs/cli": "^10.4.8",
@@ -69,6 +72,7 @@
6972
"@types/cron": "^2.4.3",
7073
"@types/express": "^5.0.0",
7174
"@types/jest": "29.5.14",
75+
"@types/js-yaml": "^4.0.9",
7276
"@types/node": "^22.10.0",
7377
"@types/supertest": "^6.0.2",
7478
"@typescript-eslint/eslint-plugin": "8.16.0",

src/app.module.ts

+44-27
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
import { Module } from '@nestjs/common';
22
import { AppService } from 'app.service';
33
import { CqrsModule } from '@nestjs/cqrs';
4-
import { ClientsModule, Transport } from '@nestjs/microservices';
5-
import { REDIS_HOST, REDIS_PASSWORD, REDIS_PORT, REDIS_URL } from 'env';
4+
import { ClientsModule, RedisOptions, Transport } from '@nestjs/microservices';
65
import { GameServerDomain } from 'gameserver';
76
import { CoreController } from 'core.controller';
87
import { TypeOrmModule } from '@nestjs/typeorm';
9-
import { Entities, prodDbConfig } from 'util/typeorm-config';
8+
import { Entities } from 'util/typeorm-config';
109
import { QueryController } from 'query.controller';
1110
import { Mapper } from 'rest/mapper';
1211
import { PlayerController } from 'rest/player.controller';
@@ -17,7 +16,6 @@ import { MetaController } from 'rest/meta/meta.controller';
1716
import { MetaService } from 'rest/meta/meta.service';
1817
import { GetUserInfoQuery } from 'gateway/queries/GetUserInfo/get-user-info.query';
1918
import { outerQuery } from 'gateway/util/outerQuery';
20-
import { QueryCache } from 'rcache';
2119
import { CacheModule } from '@nestjs/cache-manager';
2220
import { MatchService } from 'rest/match/match.service';
2321
import { MatchMapper } from 'rest/match/match.mapper';
@@ -26,36 +24,55 @@ import { MetaMapper } from 'rest/meta/meta.mapper';
2624
import { InfoMapper } from 'rest/info/info.mapper';
2725
import { InfoService } from 'rest/info/info.service';
2826
import { CrimeController } from 'rest/crime/crime.controller';
29-
30-
31-
export function qCache<T, B>() {
32-
return new QueryCache<T, B>({
33-
url: REDIS_URL(),
34-
password: REDIS_PASSWORD(),
35-
ttl: 10,
36-
});
37-
}
27+
import configuration from 'util/configuration';
28+
import { ConfigModule, ConfigService } from '@nestjs/config';
29+
import { TypeOrmModuleOptions } from '@nestjs/typeorm/dist/interfaces/typeorm-options.interface';
3830

3931
@Module({
4032
imports: [
33+
ConfigModule.forRoot({
34+
isGlobal: true,
35+
load: [configuration],
36+
}),
4137
CacheModule.register(),
4238
ScheduleModule.forRoot(),
4339
CqrsModule,
44-
TypeOrmModule.forRoot(
45-
prodDbConfig
46-
),
40+
TypeOrmModule.forRootAsync({
41+
useFactory(config: ConfigService): TypeOrmModuleOptions {
42+
return {
43+
type: "postgres",
44+
database: "postgres",
45+
host: config.get("postgres.host"),
46+
username: config.get("postgres.username"),
47+
password: config.get("postgres.password"),
48+
entities: Entities,
49+
50+
port: 5432,
51+
synchronize: true,
52+
dropSchema: false,
53+
poolSize: 50,
54+
55+
ssl: false,
56+
};
57+
},
58+
imports: [],
59+
inject: [ConfigService],
60+
}),
4761
TypeOrmModule.forFeature(Entities),
48-
ClientsModule.register([
62+
ClientsModule.registerAsync([
4963
{
50-
name: 'QueryCore',
51-
transport: Transport.REDIS,
52-
options: {
53-
host: REDIS_HOST(),
54-
port: parseInt(REDIS_PORT() as string),
55-
retryAttempts: Infinity,
56-
password: REDIS_PASSWORD(),
57-
retryDelay: 5000,
64+
name: "QueryCore",
65+
useFactory(config: ConfigService): RedisOptions {
66+
return {
67+
transport: Transport.REDIS,
68+
options: {
69+
host: config.get("redis.host"),
70+
password: config.get("redis.password"),
71+
},
72+
};
5873
},
74+
inject: [ConfigService],
75+
imports: [],
5976
},
6077
]),
6178
],
@@ -66,7 +83,7 @@ export function qCache<T, B>() {
6683
PlayerController,
6784
InfoController,
6885
MetaController,
69-
CrimeController
86+
CrimeController,
7087
],
7188
providers: [
7289
AppService,
@@ -79,7 +96,7 @@ export function qCache<T, B>() {
7996
InfoService,
8097
Mapper,
8198
...GameServerDomain,
82-
outerQuery(GetUserInfoQuery, 'QueryCore', qCache())
99+
outerQuery(GetUserInfoQuery, "QueryCore"),
83100
],
84101
})
85102
export class AppModule {}

src/core.controller.ts

+6-4
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,27 @@ import { PlayerBanHammeredEvent } from 'gateway/events/bans/player-ban-hammered.
1010
import { ServerSessionSyncEvent } from 'gateway/events/gs/server-session-sync.event';
1111
import { PlayerNotLoadedEvent } from 'gateway/events/bans/player-not-loaded.event';
1212
import { PlayerDeclinedGameEvent } from 'gateway/events/mm/player-declined-game.event';
13-
import { isDev } from 'env';
1413
import { TournamentGameReadyEvent } from 'gateway/events/tournament/tournament-game-ready.event';
1514
import { LiveMatchUpdateEvent } from 'gateway/events/gs/live-match-update.event';
1615
import { StartFakeMatchEvent } from 'gateway/events/start-fake-match.event';
1716
import { ServerStatusEvent } from 'gateway/events/gs/server-status.event';
1817
import { MatchFailedEvent } from 'gateway/events/match-failed.event';
1918
import { PlayerAbandonedEvent } from 'gateway/events/bans/player-abandoned.event';
2019
import { LobbyReadyEvent } from 'gateway/events/lobby-ready.event';
21-
20+
import { ConfigService } from '@nestjs/config';
2221

2322
@Controller()
2423
export class CoreController {
25-
constructor(private readonly ebus: EventBus) {}
24+
constructor(
25+
private readonly ebus: EventBus,
26+
private readonly config: ConfigService,
27+
) {}
2628
private readonly logger = new Logger(CoreController.name);
2729

2830
private event<T>(constructor: Constructor<T>, data: any) {
2931
const buff = data;
3032
buff.__proto__ = constructor.prototype;
31-
if (!isDev) this.ebus.publish(buff);
33+
if (this.config.get("prod")) this.ebus.publish(buff);
3234
}
3335

3436
@EventPattern(RoomReadyEvent.name)

src/env.ts

-17
This file was deleted.

0 commit comments

Comments
 (0)