Skip to content

Commit

Permalink
do not expose middleware proxy config
Browse files Browse the repository at this point in the history
  • Loading branch information
igrek8 committed Oct 17, 2022
1 parent 6f96210 commit 2438736
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 4 deletions.
3 changes: 2 additions & 1 deletion src/metric-reporter.module.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ describe('MetricReporterModule', () => {
MetricReporterModule.register({
reporter: new MetricReporter('apiKey'),
collector: { collect: (_req, _res, metric) => ({ ...metric, _id: '1' }) },
configure: (middleware) => middleware.forRoutes('*'),
routes: ['*'],
excludedRoutes: ['/health'],
}),
],
}).compile();
Expand Down
4 changes: 3 additions & 1 deletion src/metric-reporter.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ export class MetricReporterModule extends ConfigurableModuleClass implements OnM
}

configure(consumer: MiddlewareConsumer) {
this.options.configure(consumer.apply(MetricReporterMiddleware));
const config = consumer.apply(MetricReporterMiddleware);
if (this.options.excludedRoutes) config.exclude(...this.options.excludedRoutes);
config.forRoutes(...this.options.routes);
}
}
5 changes: 3 additions & 2 deletions src/metrics-reporter.module-options.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { MiddlewareConfigProxy, MiddlewareConsumer } from '@nestjs/common/interfaces';
import { RouteInfo } from '@nestjs/common/interfaces';
import { IMetricReporter } from 'readme-metric-reporter';
import { IMetricCollector } from 'readme-metric-reporter-express';

export interface MetricReporterModuleOptions {
reporter: IMetricReporter;
collector: IMetricCollector;
configure(config: MiddlewareConfigProxy): MiddlewareConsumer;
routes: (string | RouteInfo)[];
excludedRoutes?: (string | RouteInfo)[];
}

0 comments on commit 2438736

Please sign in to comment.