1
1
import { Module } from '@nestjs/common' ;
2
2
import { AppService } from 'app.service' ;
3
3
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' ;
6
5
import { GameServerDomain } from 'gameserver' ;
7
6
import { CoreController } from 'core.controller' ;
8
7
import { TypeOrmModule } from '@nestjs/typeorm' ;
9
- import { Entities , prodDbConfig } from 'util/typeorm-config' ;
8
+ import { Entities } from 'util/typeorm-config' ;
10
9
import { QueryController } from 'query.controller' ;
11
10
import { Mapper } from 'rest/mapper' ;
12
11
import { PlayerController } from 'rest/player.controller' ;
@@ -17,7 +16,6 @@ import { MetaController } from 'rest/meta/meta.controller';
17
16
import { MetaService } from 'rest/meta/meta.service' ;
18
17
import { GetUserInfoQuery } from 'gateway/queries/GetUserInfo/get-user-info.query' ;
19
18
import { outerQuery } from 'gateway/util/outerQuery' ;
20
- import { QueryCache } from 'rcache' ;
21
19
import { CacheModule } from '@nestjs/cache-manager' ;
22
20
import { MatchService } from 'rest/match/match.service' ;
23
21
import { MatchMapper } from 'rest/match/match.mapper' ;
@@ -26,36 +24,55 @@ import { MetaMapper } from 'rest/meta/meta.mapper';
26
24
import { InfoMapper } from 'rest/info/info.mapper' ;
27
25
import { InfoService } from 'rest/info/info.service' ;
28
26
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' ;
38
30
39
31
@Module ( {
40
32
imports : [
33
+ ConfigModule . forRoot ( {
34
+ isGlobal : true ,
35
+ load : [ configuration ] ,
36
+ } ) ,
41
37
CacheModule . register ( ) ,
42
38
ScheduleModule . forRoot ( ) ,
43
39
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
+ } ) ,
47
61
TypeOrmModule . forFeature ( Entities ) ,
48
- ClientsModule . register ( [
62
+ ClientsModule . registerAsync ( [
49
63
{
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
+ } ;
58
73
} ,
74
+ inject : [ ConfigService ] ,
75
+ imports : [ ] ,
59
76
} ,
60
77
] ) ,
61
78
] ,
@@ -66,7 +83,7 @@ export function qCache<T, B>() {
66
83
PlayerController ,
67
84
InfoController ,
68
85
MetaController ,
69
- CrimeController
86
+ CrimeController ,
70
87
] ,
71
88
providers : [
72
89
AppService ,
@@ -79,7 +96,7 @@ export function qCache<T, B>() {
79
96
InfoService ,
80
97
Mapper ,
81
98
...GameServerDomain ,
82
- outerQuery ( GetUserInfoQuery , ' QueryCore' , qCache ( ) )
99
+ outerQuery ( GetUserInfoQuery , " QueryCore" ) ,
83
100
] ,
84
101
} )
85
102
export class AppModule { }
0 commit comments