fix(mail): resolve templates from __dirname so they exist in the built image
The Docker runtime image only ships dist/, but mail-config.service.ts pointed at src/mail/mail-templates and nest-cli.json never copied the .hbs files into dist/ either. This was silently masked before because the return-before-sendMail bug meant the path was never touched; fixing that bug now surfaces it as a hard crash on boot (readFileSync throwing synchronously inside the MailerModule factory). Resolve the templates dir from __dirname instead, which is correct in both dev (src/mail) and the compiled image (dist/mail), and add the mail-templates .hbs files to nest-cli.json's asset copy list so they actually land in dist/.
This commit is contained in:
@@ -3,6 +3,6 @@
|
|||||||
"collection": "@nestjs/schematics",
|
"collection": "@nestjs/schematics",
|
||||||
"sourceRoot": "src",
|
"sourceRoot": "src",
|
||||||
"compilerOptions": {
|
"compilerOptions": {
|
||||||
"assets": [{ "include": "i18n/**/*", "watchAssets": true }]
|
"assets": [{ "include": "mail/mail-templates/**/*.hbs", "watchAssets": true }]
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,12 +11,10 @@ export class MailConfigService implements MailerOptionsFactory {
|
|||||||
constructor(private configService: ConfigService) {}
|
constructor(private configService: ConfigService) {}
|
||||||
|
|
||||||
createMailerOptions(): MailerOptions {
|
createMailerOptions(): MailerOptions {
|
||||||
const templatesDir = path.join(
|
// __dirname resolves to src/mail in dev (ts-node) and dist/mail in the
|
||||||
this.configService.get('app.workingDirectory'),
|
// built image, so this stays correct without depending on whether the
|
||||||
'src',
|
// process was started from a source or compiled checkout.
|
||||||
'mail',
|
const templatesDir = path.join(__dirname, 'mail-templates');
|
||||||
'mail-templates',
|
|
||||||
);
|
|
||||||
|
|
||||||
handlebars.registerPartial(
|
handlebars.registerPartial(
|
||||||
'layout',
|
'layout',
|
||||||
|
|||||||
Reference in New Issue
Block a user