There can be more than Notion and Miro. AFFiNE(pronounced [ə‘fain]) is a next-gen knowledge base that brings planning, sorting and creating all together. Privacy first, open-source, customizable and ready to use.
TypeScript appcrdteditorelectronknowledge-basemarkdownmironotesnotionnotion-alternativerustrust-langrust-languagetabletableviewwhiteboardwikiworkspace
fix(server): use ClsInterceptor on websocket (#9859)
fengmk28021b8994433
diff --git a/packages/backend/server/src/app.module.ts b/packages/backend/server/src/app.module.tsindex 86a7ff034e..98719c3d80 100644--- a/packages/backend/server/src/app.module.ts+++ b/packages/backend/server/src/app.module.ts@@ -52,17 +52,28 @@ import { ENABLED_PLUGINS } from './plugins/registry';export const FunctionalityModules = [ClsModule.forRoot({global: true,+ // for http / graphql requestmiddleware: {mount: true,generateId: true,idGenerator() {// make every request has a unique id to tracing- return randomUUID();+ return `req-${randomUUID()}`;},setup(cls, _req, res: Response) {res.setHeader('X-Request-Id', cls.getId());},},+ // for websocket connection+ // https://papooch.github.io/nestjs-cls/considerations/compatibility#websockets+ interceptor: {+ mount: true,+ generateId: true,+ idGenerator() {+ // make every request has a unique id to tracing+ return `ws-${randomUUID()}`;+ },+ },plugins: [// https://papooch.github.io/nestjs-cls/plugins/available-plugins/transactional/prisma-adapternew ClsPluginTransactional({diff --git a/packages/backend/server/src/core/sync/gateway.ts b/packages/backend/server/src/core/sync/gateway.tsindex c21b61a6f5..d0e47fa085 100644--- a/packages/backend/server/src/core/sync/gateway.ts+++ b/packages/backend/server/src/core/sync/gateway.ts@@ -1,4 +1,4 @@-import { applyDecorators, Logger } from '@nestjs/common';+import { applyDecorators, Logger, UseInterceptors } from '@nestjs/common';import {ConnectedSocket,MessageBody,@@ -7,6 +7,7 @@ import {SubscribeMessage as RawSubscribeMessage,WebSocketGateway,} from '@nestjs/websockets';+import { ClsInterceptor } from 'nestjs-cls';import { Socket } from 'socket.io';import {@@ -131,6 +132,7 @@ interface UpdateAwarenessMessage {}@WebSocketGateway()+@UseInterceptors(ClsInterceptor)export class SpaceSyncGatewayimplements OnGatewayConnection, OnGatewayDisconnect{@@ -147,11 +149,13 @@ export class SpaceSyncGatewayhandleConnection() {this.connectionCount++;+ this.logger.log(`New connection, total: ${this.connectionCount}`);metrics.socketio.gauge('realtime_connections').record(this.connectionCount);}handleDisconnect() {this.connectionCount--;+ this.logger.log(`Connection disconnected, total: ${this.connectionCount}`);metrics.socketio.gauge('realtime_connections').record(this.connectionCount);}