gemercheung 2 jaren geleden
bovenliggende
commit
df9a35c68c
5 gewijzigde bestanden met toevoegingen van 40 en 8 verwijderingen
  1. 2 2
      .env.production
  2. 22 0
      ecosystem.config.js
  3. 3 1
      package.json
  4. 10 0
      pnpm-lock.yaml
  5. 3 5
      src/room/room.service.ts

+ 2 - 2
.env.production

@@ -1,10 +1,10 @@
 APP_PORT=8888
-SOCKET_NAME='socket-test'
+SOCKET_NAME='socket-prod'
 SOCKET_PORT=8889
 SOCKET_PATH="/ws-sync"
 REDIS_HOST=127.0.0.1
 REDIS_PORT=6379
-REDIS_PASSWORD=redis9394
+REDIS_PASSWORD=JK20220120JIK
 REDIS_DB=0
 REDIS_ADAPTER_DB=8
 REDIS_PREFIX=chat

+ 22 - 0
ecosystem.config.js

@@ -0,0 +1,22 @@
+const appName = process.env.SOCKET_NAME;
+consola.log('appName', appName);
+
+module.exports = {
+  apps: [
+    {
+      name: appName,
+      exec_mode: 'cluster',
+      instances: 'max',
+      script: './dist/main.js',
+      args: '',
+      env: {
+        NODE_ENV: 'production',
+      },
+      detached: true,
+      max_restarts: 3,
+      restart_delay: 5000,
+      log_date_format: 'YYYY-MM-DD HH:mm:ss',
+      combine_logs: false,
+    },
+  ],
+};

+ 3 - 1
package.json

@@ -7,11 +7,12 @@
   "license": "UNLICENSED",
   "scripts": {
     "build": "nest build",
-    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\"",
+    "format": "prettier --write \"src/**/*.ts\" \"test/**/*.ts\" ecosystem.config.js",
     "start": "nest start",
     "start:dev": "nest start --watch",
     "start:debug": "nest start --debug --watch",
     "start:prod": "node dist/main",
+    "pm2:prod": "cross-env pm2 start -- ecosystem.config.js",
     "lint": "eslint \"{src,apps,libs,test}/**/*.ts\" --fix",
     "test": "jest",
     "test:watch": "jest --watch",
@@ -58,6 +59,7 @@
     "@types/supertest": "^2.0.11",
     "@typescript-eslint/eslint-plugin": "^5.0.0",
     "@typescript-eslint/parser": "^5.0.0",
+    "cross-env": "^7.0.3",
     "eslint": "^8.0.1",
     "eslint-config-prettier": "^8.3.0",
     "eslint-plugin-prettier": "^4.0.0",

+ 10 - 0
pnpm-lock.yaml

@@ -24,6 +24,7 @@ specifiers:
   bcrypt: ^5.1.0
   camelcase-keys: ^8.0.2
   chalk: ^4
+  cross-env: ^7.0.3
   dayjs: ^1.11.7
   dotenv: ^16.0.3
   eslint: ^8.0.1
@@ -89,6 +90,7 @@ devDependencies:
   '@types/supertest': 2.0.12
   '@typescript-eslint/eslint-plugin': 5.52.0_6cfvjsbua5ptj65675bqcn6oza
   '@typescript-eslint/parser': 5.52.0_7kw3g6rralp5ps6mg3uyzz6azm
+  cross-env: 7.0.3
   eslint: 8.34.0
   eslint-config-prettier: 8.6.0_eslint@8.34.0
   eslint-plugin-prettier: 4.2.1_u5wnrdwibbfomslmnramz52buy
@@ -2455,6 +2457,14 @@ packages:
     resolution: {integrity: sha512-dcKFX3jn0MpIaXjisoRvexIJVEKzaq7z2rZKxf+MSr9TkdmHmsU4m2lcLojrj/FHl8mk5VxMmYA+ftRkP/3oKQ==}
     dev: true
 
+  /cross-env/7.0.3:
+    resolution: {integrity: sha512-+/HKd6EgcQCJGh2PSjZuUitQBQynKor4wrFbRg4DtAgS1aWO+gU52xpH7M9ScGgXSYmAVS9bIJ8EzuaGw0oNAw==}
+    engines: {node: '>=10.14', npm: '>=6', yarn: '>=1'}
+    hasBin: true
+    dependencies:
+      cross-spawn: 7.0.3
+    dev: true
+
   /cross-spawn/7.0.3:
     resolution: {integrity: sha512-iRDPJKUPVEND7dHPO8rkbOnPpyDygcDFtWjpeWNCgy8WP2rXcxXL8TskReQl6OrB2G7+UJrags1q15Fudc7G6w==}
     engines: {node: '>= 8'}

+ 3 - 5
src/room/room.service.ts

@@ -17,12 +17,11 @@ export class RoomService {
     private readonly actionsService: ActionsService,
     private readonly delayService: DelayService,
     private readonly tempService: TempService,
-  ) { }
+  ) {}
   public readonly logger = new Logger('user');
   public _sleep = (ms: number) => new Promise((r) => setTimeout(r, ms));
   public _userInfo = {} as UserInfoType;
-  private _roomConfig = {} as RoomConfigType;
-  private isJoin = false;
+
   private get _roomId(): string {
     return this._userInfo.RoomId;
   }
@@ -113,7 +112,6 @@ export class RoomService {
     const { RoomId, UserId, Role } = socket.data.user;
 
     if (RoomId?.length && UserId?.length) {
-
       //房主设置房间配置
       if (this._isLeader) {
         const isValid = await this.userService.isRoomMaster(RoomId, UserId);
@@ -178,7 +176,7 @@ export class RoomService {
             members: roomUsers,
           });
         }
-        this.isJoin = true;
+        // this.isJoin = true;
         this.logger.log(
           JSON.stringify(socket.data.user),
           `join-user-${socket.data.user.Role}`,