This commit is contained in:
Kirill
2026-05-25 23:06:41 +05:00
parent 09c5e0cd50
commit e5e1e01c7e
4 changed files with 74 additions and 44 deletions
+1 -1
View File
@@ -4,7 +4,7 @@
"private": true,
"type": "module",
"scripts": {
"dev": "node --env-file=.env --watch-path=./src src/index.js",
"dev": "node --env-file=.env --unhandled-rejections=warn --watch src/index.js",
"dev:classic": "node --watch src/index.js",
"start": "node src/index.js",
"db:migrate": "prisma migrate dev",
Binary file not shown.
+25 -3
View File
@@ -141,10 +141,24 @@ await registerUserNotificationRoutes(fastify)
await registerOAuthSocialRoutes(fastify)
await registerYookassaWebhookRoute(fastify)
await registerApiRoutes(fastify)
await ensureAdminUser()
await getOrCreateUnspecifiedCategory()
await notificationQueue.flushPendingOnStartup()
try {
await ensureAdminUser()
} catch (err) {
fastify.log.error({ err }, 'ensureAdminUser failed — continuing startup')
}
try {
await getOrCreateUnspecifiedCategory()
} catch (err) {
fastify.log.error({ err }, 'getOrCreateUnspecifiedCategory failed — continuing startup')
}
try {
await notificationQueue.flushPendingOnStartup()
} catch (err) {
fastify.log.error({ err }, 'notificationQueue.flushPendingOnStartup failed')
}
notificationQueue.start()
const {
@@ -158,6 +172,7 @@ const {
} = NOTIFICATION_EVENTS
async function dispatchNotification(eventType, payload) {
try {
if (eventType === AUTH_CODE_REQUESTED) {
const targets = await resolveAuthCodeTargets(eventType, payload)
for (const target of targets.filter((t) => t.channel === 'telegram')) {
@@ -201,6 +216,9 @@ async function dispatchNotification(eventType, payload) {
})
notificationQueue.enqueue({ ...target, eventType, payload, logId: log.id })
}
} catch (err) {
console.error(`[notification] Error dispatching ${eventType}:`, err.message)
}
}
eventBus.on(ORDER_CREATED, (payload) => dispatchNotification(ORDER_CREATED, payload))
@@ -221,6 +239,10 @@ async function shutdown() {
process.on('SIGINT', shutdown)
process.on('SIGTERM', shutdown)
process.on('unhandledRejection', (reason) => {
console.error('[process] Unhandled rejection:', reason?.message || reason)
})
try {
await fastify.listen({ port, host: '0.0.0.0' })
} catch (err) {
+8
View File
@@ -9,6 +9,9 @@ function createTransporter() {
host: process.env.SMTP_HOST,
port: Number(process.env.SMTP_PORT),
secure: process.env.SMTP_SECURE === 'true',
connectionTimeout: 5000,
greetingTimeout: 5000,
socketTimeout: 5000,
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS,
@@ -22,6 +25,7 @@ export async function sendLoginCodeEmail({ to, code }) {
return
}
try {
const transporter = createTransporter()
const from = process.env.MAIL_FROM || process.env.SMTP_USER
@@ -31,6 +35,10 @@ export async function sendLoginCodeEmail({ to, code }) {
subject: 'Код входа',
text: `Ваш код: ${code}\n\nЕсли это были не вы — просто проигнорируйте письмо.`,
})
} catch (err) {
console.error(`[email] Failed to send login code to ${to}: ${err.message}`)
console.info(`[DEV] login code for ${to}: ${code}`)
}
}
export async function sendNotificationEmail({ to, subject, html }) {