Browse Source

fix(email-plugin): Add warning when running devMode with transport

Fixes #2253
Michael Bromley 2 years ago
parent
commit
7498901222
1 changed files with 8 additions and 21 deletions
  1. 8 21
      packages/email-plugin/src/email-processor.ts

+ 8 - 21
packages/email-plugin/src/email-processor.ts

@@ -29,12 +29,6 @@ import {
 export class EmailProcessor {
 export class EmailProcessor {
     protected emailSender: EmailSender;
     protected emailSender: EmailSender;
     protected generator: EmailGenerator;
     protected generator: EmailGenerator;
-    protected transport:
-        | EmailTransportOptions
-        | ((
-              injector?: Injector,
-              ctx?: RequestContext,
-          ) => EmailTransportOptions | Promise<EmailTransportOptions>);
 
 
     constructor(
     constructor(
         @Inject(EMAIL_PLUGIN_OPTIONS) protected options: InitializedEmailPluginOptions,
         @Inject(EMAIL_PLUGIN_OPTIONS) protected options: InitializedEmailPluginOptions,
@@ -49,20 +43,6 @@ export class EmailProcessor {
         if (this.generator.onInit) {
         if (this.generator.onInit) {
             await this.generator.onInit.call(this.generator, this.options);
             await this.generator.onInit.call(this.generator, this.options);
         }
         }
-        if (isDevModeOptions(this.options)) {
-            this.transport = {
-                type: 'file',
-                raw: false,
-                outputPath: this.options.outputPath,
-            };
-        } else {
-            if (!this.options.transport) {
-                throw new InternalServerError(
-                    "When devMode is not set to true, the 'transport' property must be set.",
-                );
-            }
-            this.transport = this.options.transport;
-        }
         const transport = await this.getTransportSettings();
         const transport = await this.getTransportSettings();
         if (transport.type === 'file') {
         if (transport.type === 'file') {
             // ensure the configured directory exists before
             // ensure the configured directory exists before
@@ -106,14 +86,21 @@ export class EmailProcessor {
     }
     }
 
 
     async getTransportSettings(ctx?: RequestContext): Promise<EmailTransportOptions> {
     async getTransportSettings(ctx?: RequestContext): Promise<EmailTransportOptions> {
+        const transport = await resolveTransportSettings(this.options, new Injector(this.moduleRef), ctx);
         if (isDevModeOptions(this.options)) {
         if (isDevModeOptions(this.options)) {
+            if (transport && transport.type !== 'file') {
+                Logger.warn(
+                    `The EmailPlugin is running in dev mode. The configured '${transport.type}' transport will be replaced by the 'file' transport.`,
+                    loggerCtx,
+                );
+            }
             return {
             return {
                 type: 'file',
                 type: 'file',
                 raw: false,
                 raw: false,
                 outputPath: this.options.outputPath,
                 outputPath: this.options.outputPath,
             };
             };
         } else {
         } else {
-            return resolveTransportSettings(this.options, new Injector(this.moduleRef), ctx);
+            return transport;
         }
         }
     }
     }
 }
 }