mirror of
https://github.com/docmost/docmost.git
synced 2025-11-15 22:51:09 +10:00
feat: standalone collab server (#767)
* feat: standalone collab server * * custom collab server port env * fix collab start script command * * API prefix * Log startup PORT * Tweak collab debounce
This commit is contained in:
@ -25,21 +25,25 @@ export class CollaborationGateway {
|
||||
this.redisConfig = parseRedisUrl(this.environmentService.getRedisUrl());
|
||||
|
||||
this.hocuspocus = HocuspocusServer.configure({
|
||||
debounce: 5000,
|
||||
maxDebounce: 10000,
|
||||
debounce: 10000,
|
||||
maxDebounce: 20000,
|
||||
unloadImmediately: false,
|
||||
extensions: [
|
||||
this.authenticationExtension,
|
||||
this.persistenceExtension,
|
||||
new Redis({
|
||||
host: this.redisConfig.host,
|
||||
port: this.redisConfig.port,
|
||||
options: {
|
||||
password: this.redisConfig.password,
|
||||
db: this.redisConfig.db,
|
||||
retryStrategy: createRetryStrategy(),
|
||||
},
|
||||
}),
|
||||
...(this.environmentService.isCollabDisableRedis()
|
||||
? []
|
||||
: [
|
||||
new Redis({
|
||||
host: this.redisConfig.host,
|
||||
port: this.redisConfig.port,
|
||||
options: {
|
||||
password: this.redisConfig.password,
|
||||
db: this.redisConfig.db,
|
||||
retryStrategy: createRetryStrategy(),
|
||||
},
|
||||
}),
|
||||
]),
|
||||
],
|
||||
});
|
||||
}
|
||||
@ -48,6 +52,14 @@ export class CollaborationGateway {
|
||||
this.hocuspocus.handleConnection(client, request);
|
||||
}
|
||||
|
||||
getConnectionCount() {
|
||||
return this.hocuspocus.getConnectionsCount();
|
||||
}
|
||||
|
||||
getDocumentCount() {
|
||||
return this.hocuspocus.getDocumentsCount();
|
||||
}
|
||||
|
||||
async destroy(): Promise<void> {
|
||||
await this.hocuspocus.destroy();
|
||||
}
|
||||
|
||||
23
apps/server/src/collaboration/server/collab-app.module.ts
Normal file
23
apps/server/src/collaboration/server/collab-app.module.ts
Normal file
@ -0,0 +1,23 @@
|
||||
import { Module } from '@nestjs/common';
|
||||
import { AppController } from '../../app.controller';
|
||||
import { AppService } from '../../app.service';
|
||||
import { EnvironmentModule } from '../../integrations/environment/environment.module';
|
||||
import { CollaborationModule } from '../collaboration.module';
|
||||
import { DatabaseModule } from '@docmost/db/database.module';
|
||||
import { QueueModule } from '../../integrations/queue/queue.module';
|
||||
import { EventEmitterModule } from '@nestjs/event-emitter';
|
||||
import { HealthModule } from '../../integrations/health/health.module';
|
||||
|
||||
@Module({
|
||||
imports: [
|
||||
DatabaseModule,
|
||||
EnvironmentModule,
|
||||
CollaborationModule,
|
||||
QueueModule,
|
||||
HealthModule,
|
||||
EventEmitterModule.forRoot(),
|
||||
],
|
||||
controllers: [AppController],
|
||||
providers: [AppService],
|
||||
})
|
||||
export class CollabAppAppModule {}
|
||||
39
apps/server/src/collaboration/server/collab-main.ts
Normal file
39
apps/server/src/collaboration/server/collab-main.ts
Normal file
@ -0,0 +1,39 @@
|
||||
import { NestFactory } from '@nestjs/core';
|
||||
import { CollabAppAppModule } from './collab-app.module';
|
||||
import {
|
||||
FastifyAdapter,
|
||||
NestFastifyApplication,
|
||||
} from '@nestjs/platform-fastify';
|
||||
import { TransformHttpResponseInterceptor } from '../../common/interceptors/http-response.interceptor';
|
||||
import { InternalLogFilter } from '../../common/logger/internal-log-filter';
|
||||
import { Logger } from '@nestjs/common';
|
||||
|
||||
async function bootstrap() {
|
||||
const app = await NestFactory.create<NestFastifyApplication>(
|
||||
CollabAppAppModule,
|
||||
new FastifyAdapter({
|
||||
ignoreTrailingSlash: true,
|
||||
ignoreDuplicateSlashes: true,
|
||||
maxParamLength: 500,
|
||||
}),
|
||||
{
|
||||
logger: new InternalLogFilter(),
|
||||
},
|
||||
);
|
||||
|
||||
app.setGlobalPrefix('api', { exclude: ['/'] });
|
||||
|
||||
app.enableCors();
|
||||
|
||||
app.useGlobalInterceptors(new TransformHttpResponseInterceptor());
|
||||
app.enableShutdownHooks();
|
||||
|
||||
const logger = new Logger('CollabServer');
|
||||
|
||||
const port = process.env.COLLAB_PORT || 3001;
|
||||
await app.listen(port, '0.0.0.0', () => {
|
||||
logger.log(`Listening on http://127.0.0.1:${port}`);
|
||||
});
|
||||
}
|
||||
|
||||
bootstrap();
|
||||
@ -145,4 +145,15 @@ export class EnvironmentService {
|
||||
isSelfHosted(): boolean {
|
||||
return !this.isCloud();
|
||||
}
|
||||
|
||||
getCollabUrl(): string {
|
||||
return this.configService.get<string>('COLLAB_URL');
|
||||
}
|
||||
|
||||
isCollabDisableRedis(): boolean {
|
||||
const isStandalone = this.configService
|
||||
.get<string>('COLLAB_DISABLE_REDIS', 'false')
|
||||
.toLowerCase();
|
||||
return isStandalone === 'true';
|
||||
}
|
||||
}
|
||||
|
||||
@ -5,6 +5,7 @@ import {
|
||||
IsOptional,
|
||||
IsUrl,
|
||||
MinLength,
|
||||
ValidateIf,
|
||||
validateSync,
|
||||
} from 'class-validator';
|
||||
import { plainToInstance } from 'class-transformer';
|
||||
@ -48,6 +49,11 @@ export class EnvironmentVariables {
|
||||
@IsOptional()
|
||||
@IsIn(['local', 's3'])
|
||||
STORAGE_DRIVER: string;
|
||||
|
||||
@IsOptional()
|
||||
@ValidateIf((obj) => obj.COLLAB_URL != '' && obj.COLLAB_URL != null)
|
||||
@IsUrl({ protocols: ['http', 'https'], require_tld: false })
|
||||
COLLAB_URL: string;
|
||||
}
|
||||
|
||||
export function validate(config: Record<string, any>) {
|
||||
|
||||
@ -38,6 +38,7 @@ export class StaticModule implements OnModuleInit {
|
||||
FILE_UPLOAD_SIZE_LIMIT:
|
||||
this.environmentService.getFileUploadSizeLimit(),
|
||||
DRAWIO_URL: this.environmentService.getDrawioUrl(),
|
||||
COLLAB_URL: this.environmentService.getCollabUrl(),
|
||||
};
|
||||
|
||||
const windowScriptContent = `<script>window.CONFIG=${JSON.stringify(configString)};</script>`;
|
||||
|
||||
Reference in New Issue
Block a user