server: use configService

This commit is contained in:
fantasticit 2022-05-21 14:54:35 +08:00
parent c32e1f9894
commit f57e2bf23c
3 changed files with 19 additions and 4 deletions

View File

@ -8,12 +8,14 @@ import { UserModule } from '@modules/user.module';
import { ViewModule } from '@modules/view.module'; import { ViewModule } from '@modules/view.module';
import { WikiModule } from '@modules/wiki.module'; import { WikiModule } from '@modules/wiki.module';
import { forwardRef, Module } from '@nestjs/common'; import { forwardRef, Module } from '@nestjs/common';
import { ConfigModule } from '@nestjs/config';
import { TypeOrmModule } from '@nestjs/typeorm'; import { TypeOrmModule } from '@nestjs/typeorm';
import { DocumentService } from '@services/document.service'; import { DocumentService } from '@services/document.service';
@Module({ @Module({
imports: [ imports: [
TypeOrmModule.forFeature([DocumentAuthorityEntity, DocumentEntity]), TypeOrmModule.forFeature([DocumentAuthorityEntity, DocumentEntity]),
forwardRef(() => ConfigModule),
forwardRef(() => UserModule), forwardRef(() => UserModule),
forwardRef(() => WikiModule), forwardRef(() => WikiModule),
forwardRef(() => MessageModule), forwardRef(() => MessageModule),

View File

@ -1,6 +1,7 @@
import { onAuthenticatePayload, onChangePayload, onLoadDocumentPayload, Server } from '@hocuspocus/server'; import { onAuthenticatePayload, onChangePayload, onLoadDocumentPayload, Server } from '@hocuspocus/server';
import { TiptapTransformer } from '@hocuspocus/transformer'; import { TiptapTransformer } from '@hocuspocus/transformer';
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { DocumentService } from '@services/document.service'; import { DocumentService } from '@services/document.service';
import { DocumentVersionService } from '@services/document-version.service'; import { DocumentVersionService } from '@services/document-version.service';
import { TemplateService } from '@services/template.service'; import { TemplateService } from '@services/template.service';
@ -26,12 +27,18 @@ export class CollaborationService {
constructor( constructor(
@Inject(forwardRef(() => UserService)) @Inject(forwardRef(() => UserService))
private readonly userService: UserService, private readonly userService: UserService,
@Inject(forwardRef(() => DocumentService)) @Inject(forwardRef(() => DocumentService))
private readonly documentService: DocumentService, private readonly documentService: DocumentService,
@Inject(forwardRef(() => TemplateService)) @Inject(forwardRef(() => TemplateService))
private readonly templateService: TemplateService, private readonly templateService: TemplateService,
@Inject(forwardRef(() => DocumentVersionService)) @Inject(forwardRef(() => DocumentVersionService))
private readonly documentVersionService: DocumentVersionService private readonly documentVersionService: DocumentVersionService,
@Inject(forwardRef(() => ConfigService))
private readonly configService: ConfigService
) { ) {
this.initServer(); this.initServer();
} }
@ -73,8 +80,9 @@ export class CollaborationService {
onDisconnect: this.onDisconnect.bind(this), onDisconnect: this.onDisconnect.bind(this),
}); });
this.server = server; this.server = server;
await this.server.listen(lodash.get(getConfig(), 'server.collaborationPort', 5003)); const port = this.configService.get('server.collaborationPort') || 5003;
console.log('[think] 协作服务启动成功'); await this.server.listen(port);
console.log(`[think] 协作服务启动成功,端口:${port}`);
} catch (err) { } catch (err) {
console.error('[think] 协作服务启动失败:', err.message); console.error('[think] 协作服务启动失败:', err.message);
} }

View File

@ -5,6 +5,7 @@ import { UpdateDocumentDto } from '@dtos/update-document.dto';
import { DocumentEntity } from '@entities/document.entity'; import { DocumentEntity } from '@entities/document.entity';
import { DocumentAuthorityEntity } from '@entities/document-authority.entity'; import { DocumentAuthorityEntity } from '@entities/document-authority.entity';
import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common'; import { forwardRef, HttpException, HttpStatus, Inject, Injectable } from '@nestjs/common';
import { ConfigService } from '@nestjs/config';
import { InjectRepository } from '@nestjs/typeorm'; import { InjectRepository } from '@nestjs/typeorm';
import { CollaborationService } from '@services/collaboration.service'; import { CollaborationService } from '@services/collaboration.service';
import { DocumentVersionService } from '@services/document-version.service'; import { DocumentVersionService } from '@services/document-version.service';
@ -30,6 +31,9 @@ export class DocumentService {
@InjectRepository(DocumentEntity) @InjectRepository(DocumentEntity)
public readonly documentRepo: Repository<DocumentEntity>, public readonly documentRepo: Repository<DocumentEntity>,
@Inject(forwardRef(() => ConfigService))
private readonly configService: ConfigService,
@Inject(forwardRef(() => MessageService)) @Inject(forwardRef(() => MessageService))
private readonly messageService: MessageService, private readonly messageService: MessageService,
@ -50,7 +54,8 @@ export class DocumentService {
this.userService, this.userService,
this, this,
this.templateService, this.templateService,
this.documentVersionService this.documentVersionService,
this.configService
); );
} }