Skip to content

Commit

Permalink
fix(module): set interceptor defaults
Browse files Browse the repository at this point in the history
OgmaInterceptor will now run by default and set the format option based on the existence of and
value of the NODE_ENV environment variable
  • Loading branch information
jmcdo29 committed Feb 20, 2020
1 parent 31b7819 commit 0156994
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion src/ogma.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ export class OgmaModule extends createConfigurableDynamicRootModule<
OgmaService,
{
provide: OGMA_INTERCEPTOR_OPTIONS,
useFactory: (options: OgmaModuleOptions) => options.interceptor,
useFactory: (
options: OgmaModuleOptions,
): OgmaInterceptorOptions | boolean =>
options.interceptor !== undefined ? options.interceptor : true,
inject: [OGMA_OPTIONS],
},
{
Expand All @@ -47,6 +50,11 @@ export class OgmaModule extends createConfigurableDynamicRootModule<
let interceptor;
if (options) {
options = typeof options === 'object' ? options : {};
options.format =
options.format ??
process.env.NODE_ENV?.toLowerCase().includes('prod')
? 'prod'
: 'dev';
interceptor = new OgmaInterceptor(options, service);
} else {
interceptor = {
Expand Down

0 comments on commit 0156994

Please sign in to comment.