app.module.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. import { ConfigModule } from '@nestjs/config';
  2. import { NacosService, NacosModule } from 'nest-nacos';
  3. import { getEnvPath } from './common/helper/env.helper';
  4. const envFilePath: string = getEnvPath(`${__dirname}/common/envs`);
  5. const config = ConfigModule.forRoot({
  6. isGlobal: true,
  7. envFilePath: envFilePath,
  8. });
  9. const nacosMo = NacosModule.forRoot({
  10. server: '120.24.144.164:8848',
  11. accessKey: 'testsocket',
  12. secretKey: 'testsocket',
  13. namespace: '4dkankan-v4-test',
  14. config: {
  15. group: 'DEFAULT_GROUP',
  16. dataId: '4dkakan-daikan.yaml',
  17. },
  18. });
  19. import { Module, OnModuleInit } from '@nestjs/common';
  20. import { AppController } from './app.controller';
  21. import { AppService } from './app.service';
  22. import { RedisModule, RedisService } from '@liaoliaots/nestjs-redis';
  23. import { ThrottlerModule } from '@nestjs/throttler';
  24. import { ThrottlerStorageRedisService } from 'nestjs-throttler-storage-redis';
  25. import { RoomModule } from './room/room.module';
  26. // import { SocketModule } from './socket/socket.module';
  27. import { RoomManagerModule } from './room-manager/room-manager.module';
  28. const url = `redis://:${process.env.REDIS_PASSWORD}@${process.env.REDIS_HOST}:${process.env.REDIS_PORT}/${process.env.REDIS_DB}`;
  29. const redisMo = RedisModule.forRoot({
  30. config: [
  31. {
  32. url: url,
  33. },
  34. {
  35. namespace: 'sub',
  36. url: url,
  37. },
  38. ],
  39. });
  40. const storeThor = ThrottlerModule.forRootAsync({
  41. useFactory(redisService: RedisService) {
  42. const redis = redisService.getClient();
  43. return {
  44. ttl: 60,
  45. limit: 600,
  46. storage: new ThrottlerStorageRedisService(redis),
  47. };
  48. },
  49. inject: [RedisService],
  50. });
  51. @Module({
  52. imports: [config, redisMo, storeThor, RoomModule, RoomManagerModule, nacosMo],
  53. controllers: [AppController],
  54. providers: [AppService],
  55. exports: [],
  56. })
  57. export class AppModule implements OnModuleInit {
  58. constructor(private readonly nacos: NacosService) {}
  59. async onModuleInit() {
  60. await this.nacos.register('4dkakan-daikan-socket');
  61. }
  62. }