| 33 | (MicroserviceOptions | AsyncMicroserviceOptions); |
| 34 | |
| 35 | export class NestMicroservice |
| 36 | extends NestApplicationContext<NestMicroserviceOptions> |
| 37 | implements INestMicroservice |
| 38 | { |
| 39 | protected readonly logger = new Logger(NestMicroservice.name, { |
| 40 | timestamp: true, |
| 41 | }); |
| 42 | private readonly microservicesModule = new MicroservicesModule(); |
| 43 | private readonly socketModule = SocketModule ? new SocketModule() : null; |
| 44 | private microserviceConfig: Exclude< |
| 45 | CompleteMicroserviceOptions, |
| 46 | AsyncMicroserviceOptions |
| 47 | >; |
| 48 | private serverInstance: Server; |
| 49 | private isTerminated = false; |
| 50 | private wasInitHookCalled = false; |
| 51 | |
| 52 | /** |
| 53 | * Returns an observable that emits status changes. |
| 54 | */ |
| 55 | get status() { |
| 56 | return this.serverInstance.status; |
| 57 | } |
| 58 | |
| 59 | constructor( |
| 60 | container: NestContainer, |
| 61 | config: CompleteMicroserviceOptions = {}, |
| 62 | private readonly graphInspector: GraphInspector, |
| 63 | private readonly applicationConfig: ApplicationConfig, |
| 64 | ) { |
| 65 | super(container, config); |
| 66 | |
| 67 | this.injector = new Injector({ |
| 68 | preview: config.preview!, |
| 69 | instanceDecorator: config.instrument?.instanceDecorator, |
| 70 | }); |
| 71 | this.microservicesModule.register( |
| 72 | container, |
| 73 | this.graphInspector, |
| 74 | this.applicationConfig, |
| 75 | this.appOptions, |
| 76 | ); |
| 77 | this.createServer(config); |
| 78 | this.selectContextModule(); |
| 79 | |
| 80 | const modulesContainer = this.container.getModules(); |
| 81 | modulesContainer.addRpcTarget(this.serverInstance); |
| 82 | } |
| 83 | |
| 84 | public createServer(config: CompleteMicroserviceOptions) { |
| 85 | try { |
| 86 | if ('useFactory' in config) { |
| 87 | const resolvedConfig = this.resolveAsyncOptions(config); |
| 88 | this.microserviceConfig = resolvedConfig; |
| 89 | |
| 90 | // Inject custom strategy |
| 91 | if ('strategy' in resolvedConfig) { |
| 92 | this.serverInstance = resolvedConfig.strategy as Server; |
nothing calls this directly
no outgoing calls
no test coverage detected