diff --git a/modules/router/src/Router.ts b/modules/router/src/Router.ts index d4f647d0a..c2b1d578c 100644 --- a/modules/router/src/Router.ts +++ b/modules/router/src/Router.ts @@ -44,6 +44,7 @@ import * as adminRoutes from './admin/routes/index.js'; import metricsSchema from './metrics/index.js'; import { ConfigController, ManagedModule } from '@conduitplatform/module-tools'; import { fileURLToPath } from 'node:url'; + const __filename = fileURLToPath(import.meta.url); const __dirname = path.dirname(__filename); @@ -161,9 +162,9 @@ export default class ConduitDefaultRouter extends ManagedModule { const messageParsed = JSON.parse(message); try { this.internalRegisterRoute( - messageParsed.protofile, messageParsed.routes, messageParsed.url, + messageParsed.moduleName, ); } catch (err) { ConduitGrpcSdk.Logger.error(err as Error); @@ -172,7 +173,11 @@ export default class ConduitDefaultRouter extends ManagedModule { this.scheduleMiddlewareApply(); } - updateState(routes: RegisterConduitRouteRequest_PathDefinition[], url: string) { + updateState( + routes: RegisterConduitRouteRequest_PathDefinition[], + url: string, + moduleName: string, + ) { this.grpcSdk .state!.modifyState(async (existingState: Indexable) => { const state = existingState ?? {}; @@ -189,12 +194,13 @@ export default class ConduitDefaultRouter extends ManagedModule { state.routes.push({ routes, url, + moduleName, }); } return state; }) .then(() => { - this.publishRouteData(routes, url); + this.publishRouteData(routes, url, moduleName); ConduitGrpcSdk.Logger.log('Updated routes state'); }) .catch(e => { @@ -203,12 +209,17 @@ export default class ConduitDefaultRouter extends ManagedModule { }); } - publishRouteData(routes: RegisterConduitRouteRequest_PathDefinition[], url: string) { + publishRouteData( + routes: RegisterConduitRouteRequest_PathDefinition[], + url: string, + moduleName: string, + ) { this.grpcSdk.bus!.publish( 'router', JSON.stringify({ routes, url, + moduleName, }), ); } @@ -253,7 +264,7 @@ export default class ConduitDefaultRouter extends ManagedModule { moduleName as string, ); - this.updateState(call.request.routes, call.request.routerUrl); + this.updateState(call.request.routes, call.request.routerUrl, moduleName as string); this.scheduleMiddlewareApply(); } catch (err) { ConduitGrpcSdk.Logger.error(err as Error); diff --git a/packages/admin/src/index.ts b/packages/admin/src/index.ts index 1a6aec727..11cc2e62d 100644 --- a/packages/admin/src/index.ts +++ b/packages/admin/src/index.ts @@ -383,7 +383,7 @@ export default class AdminModule extends IConduitAdmin { } }); } - return this.internalRegisterRoute(r.protofile, r.routes, r.url); + return this.internalRegisterRoute(r.routes, r.url); } catch (err) { ConduitGrpcSdk.Logger.error(err as Error); } @@ -418,9 +418,9 @@ export default class AdminModule extends IConduitAdmin { const messageParsed = JSON.parse(message); try { this.internalRegisterRoute( - messageParsed.protofile, messageParsed.routes, messageParsed.url, + messageParsed.moduleName, ); } catch (err) { ConduitGrpcSdk.Logger.error(err as Error); diff --git a/packages/core/src/config-manager/service-discovery/index.ts b/packages/core/src/config-manager/service-discovery/index.ts index 029c9261b..9ed5a2226 100644 --- a/packages/core/src/config-manager/service-discovery/index.ts +++ b/packages/core/src/config-manager/service-discovery/index.ts @@ -77,7 +77,7 @@ export class ServiceDiscovery { }); } } - this.grpcSdk.bus!.subscribe('config', (message: string) => { + this.grpcSdk.bus!.subscribe('service-discover', (message: string) => { const parsedMessage = JSON.parse(message); if (parsedMessage.type === 'module-health') { this._serviceMonitor.updateModuleHealth( @@ -233,7 +233,7 @@ export class ServiceDiscovery { status?: HealthCheckStatus, ) { this.grpcSdk.bus!.publish( - 'config', + 'service-discover', JSON.stringify({ type, name,