tsed: TypeORM and TS.ed after routes init not started

Informations

Type Version
Bug/ 4.x

Description

Hello. I have been trying to integrate TS.ed with TypeORM for a long time. I found a potential error that does not allow simultaneous integration and using componentsScan. Ff I add the typeorm and componentsScan options simultaneously when the server is started, the $ afterRoutesInit hook will not be executed in my service.

EXAMPLE:

@ServerSettings({
    rootDir,
    mount: {
        '/v1': `${rootDir}/controllers/**/**.controller.{ts,js}`
    },
    componentsScan: [
        `${rootDir}/middlewares/**/**.{ts,js}`,
        `${rootDir}/services/**/**.{ts,js}`,
    ],
    typeorm: [
        {
            name: "default",
            type: "postgres",
            host: "0.0.0.0",
            port: 5432,
            username: "postgres",
            password: "postgres",
            database: "postgres",
            synchronize: true,
            logging: false,
            entities: [
                `${__dirname}/entity/*{.ts,.js}`
            ],
            migrations: [
                `${__dirname}/migrations/*{.ts,.js}`
            ],
            subscribers: [
                `${__dirname}/subscriber/*{.ts,.js}`
            ]
        }
    ],
    httpPort: process.env.PORT || 3000,
    httpsPort: false,
    acceptMimes: ['application/json', ''],
    swagger: {
        path: '/doc'
    },
})
@Service()
export class UserService implements AfterRoutesInit {

    private connection: Connection;

    constructor(
        private typeORMService: TypeORMService
    ) {
    }

    $afterRoutesInit() {
        this.connection = this.typeORMService.get();
        $log.warn('Connected to the Users');
    }
}

In this case the $ afterRoutesInit hook will not be executed.

Can someone help me? Is there any solution that can be circumvented by this error?

Acceptance criterias

  • Example (log, usecase, etc…)
  • Ts.ED version (bug/question)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Comments: 16 (8 by maintainers)

Most upvoted comments

It works! Thanks for your help! We can close this task