-
Notifications
You must be signed in to change notification settings - Fork 0
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
PDT24-45 | Fix Docker Hot-Reloading #11
Changes from all commits
706a539
316b69e
d67158f
a339eea
5510707
5db0c73
9d9670a
ed396dd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
# custom | ||
|
||
# compiled output | ||
/dist | ||
/node_modules | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
import { format, transports } from 'winston'; | ||
import { env } from '@/config/env.config'; | ||
|
||
const isProduction = env.NODE_ENV === 'production'; | ||
export const loggerConfig = { | ||
format: format.combine( | ||
format.timestamp({ format: 'YYYY-MM-DD HH:mm:ss' }), | ||
format.printf(({ level, message, timestamp }) => { | ||
return `${timestamp} [${level}]: ${message}`; | ||
}), | ||
), | ||
transports: isProduction | ||
? [ | ||
new transports.File({ filename: 'logs/errors.log', level: 'error' }), | ||
new transports.File({ filename: 'logs/all.log' }), | ||
Comment on lines
+14
to
+15
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Use There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It turns out that the existing code (without flags: 'a') works just fine. It doesn't overwrite the log files on each rebuild. so I am leaving as it is |
||
] | ||
: [new transports.Console({ format: format.combine(format.colorize({ all: true })) })], | ||
}; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { Address } from 'nodemailer/lib/mailer'; | ||
export class MailerDto { | ||
to: Address[]; | ||
subject: string; | ||
html: string; | ||
text?: string; | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { MailerService } from '@/mailer/mailer.service'; | ||
|
||
@Module({ | ||
providers: [MailerService], | ||
exports: [MailerService], | ||
}) | ||
export class MailerModule {} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { createTransport, SendMailOptions, Transporter } from 'nodemailer'; | ||
import { Logger } from '@nestjs/common'; | ||
import { MailerDto } from '@/mailer/dto/mailer.dto'; | ||
import { env } from '@/config/env.config'; | ||
|
||
export class MailerService { | ||
private readonly logger = new Logger(); | ||
transporter: Transporter = createTransport({ | ||
host: env.EMAIL_HOST, | ||
port: env.EMAIL_PORT, | ||
secure: true, | ||
|
||
auth: { | ||
user: env.EMAIL_USER, | ||
pass: env.EMAIL_PASS, | ||
}, | ||
}); | ||
|
||
async sendEmail(data: MailerDto): Promise<void> { | ||
try { | ||
const { to, subject, html, text } = data; | ||
const mailOptions: SendMailOptions = { | ||
from: { | ||
name: env.EMAIL_SENDER_NAME as string, | ||
address: env.EMAIL_USER as string, | ||
}, | ||
to, | ||
subject, | ||
html, | ||
text, | ||
}; | ||
await this.transporter.sendMail(mailOptions); | ||
this.logger.log('Mail sent successfully'); | ||
} catch (error) { | ||
this.logger.error(`Failed to send email: ${error}`); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
export const signupOtpMailTemplate = { | ||
subject: 'Verify your account', | ||
/** | ||
* Generates a random OTP of the specified size. | ||
* @param otpCode - code to send to through email. | ||
* @param userName - name of the user to send the email to. | ||
*/ | ||
body: (otpCode: number, userName: string): string => ` | ||
<div> | ||
<p>Welcome ${userName}</p> | ||
<p>Use this code to verify your account:<br><b>${otpCode}</b> | ||
</div> | ||
`, | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If possible, store logs for different dates in different log files.
E.g. errors_2024-12-32.log
To stay clear of potential timezone issues, use server time or UTC.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For this we'd have to install an additional package called winston-daily-rotate-file. I tried to so but that package cause issues related to typescript. In future, I'll create a separate ticket for this and solve this. For now, lets keep it as it is