Новые правки

This commit is contained in:
Web-serfer 2026-05-04 04:05:35 +05:00
parent 2453421cdf
commit 35aeeca9a2

View file

@ -7,16 +7,15 @@ const forceProduction = import.meta.env.PB_POCKETBASE_URL?.includes('avt-back')
const isProduction = hasProductionFlag || forceProduction || !isDev; const isProduction = hasProductionFlag || forceProduction || !isDev;
const SMTP_HOST = isProduction const SMTP_HOST = isProduction
? (import.meta.env.SMTP_HOST || 'smtp.resend.com') ? (import.meta.env.SMTP_HOST || 'smtp.yandex.ru')
: 'localhost'; : 'localhost';
const SMTP_PORT = isProduction const SMTP_PORT = isProduction
? (import.meta.env.SMTP_PORT || '587') ? (import.meta.env.SMTP_PORT || '587')
: '1025'; : '1025';
const SMTP_AUTH_USER = isProduction ? (import.meta.env.SMTP_AUTH_USER || '') : ''; const SMTP_AUTH_USER = isProduction ? (import.meta.env.SMTP_AUTH_USER || '') : '';
const SMTP_AUTH_PASS = isProduction ? (import.meta.env.SMTP_AUTH_PASS || '') : ''; const SMTP_AUTH_PASS = isProduction ? (import.meta.env.SMTP_AUTH_PASS || '') : '';
const RESEND_API_KEY = import.meta.env.RESEND_API_KEY || SMTP_AUTH_PASS;
const FROM_EMAIL = isProduction const FROM_EMAIL = isProduction
? (import.meta.env.FROM_EMAIL || 'onboarding@resend.onlinemail.me') ? (import.meta.env.FROM_EMAIL || 'noreply@localhost')
: 'noreply@localhost'; : 'noreply@localhost';
const FROM_NAME = isProduction ? (import.meta.env.FROM_NAME || 'Автоюрист Сургут') : 'Dev'; const FROM_NAME = isProduction ? (import.meta.env.FROM_NAME || 'Автоюрист Сургут') : 'Dev';
const SITE_URL = isProduction const SITE_URL = isProduction
@ -26,11 +25,8 @@ const SITE_URL = isProduction
let transporter: nodemailer.Transporter | null = null; let transporter: nodemailer.Transporter | null = null;
console.log('[EMAIL] isDev:', isDev); console.log('[EMAIL] isDev:', isDev);
console.log('[EMAIL] hasProductionFlag:', hasProductionFlag);
console.log('[EMAIL] forceProduction:', forceProduction);
console.log('[EMAIL] isProduction:', isProduction); console.log('[EMAIL] isProduction:', isProduction);
console.log('[EMAIL] RESEND_API_KEY present:', !!RESEND_API_KEY); console.log('[EMAIL] SMTP:', SMTP_HOST, ':', SMTP_PORT);
console.log('[EMAIL] Use RESEND_API:', isProduction && !!RESEND_API_KEY);
function getTransporter() { function getTransporter() {
if (!transporter) { if (!transporter) {
@ -94,12 +90,8 @@ function withTimeout<T>(promise: Promise<T>, ms: number): Promise<T> {
} }
export async function sendEmail(options: EmailOptions): Promise<boolean> { export async function sendEmail(options: EmailOptions): Promise<boolean> {
if (isProduction && RESEND_API_KEY) {
return sendViaResendApi(options);
}
console.log('[NODEMAILER] Sending to:', options.to); console.log('[NODEMAILER] Sending to:', options.to);
console.log('[NODEMAILER] SMTP config:', { host: SMTP_HOST, port: SMTP_PORT }); console.log('[NODEMAILER] SMTP config:', { host: SMTP_HOST, port: SMTP_PORT, user: SMTP_AUTH_USER });
try { try {
const info = await withTimeout( const info = await withTimeout(