Skip to content

Startup Task #1509

Answered by detroitpro
detroitpro asked this question in Q&A
Aug 31, 2021 · 1 comments · 2 replies
Discussion options

You must be logged in to vote

I think using hooks is the answer.

export class Server {
  @Inject()
  app: PlatformApplication | undefined;

  @Inject() 
  workers: Workers | undefined; // inject `service` here.

  @Configuration()
  settings: Configuration | undefined;

  $beforeRoutesInit(): void {
    this.app
      ?.use(cors())
      .use(cookieParser())
      .use(compress({}))
      .use(methodOverride())
      .use(express.json())
      .use(express.urlencoded({ extended: true }));
  }

  async $onReady(): Promise<void> { // use $onReady hook to perform action when server is started
    await this.workers?.init();
  }
}

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@Romakita
Comment options

@Romakita
Comment options

Answer selected by Romakita
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants