test
This commit is contained in:
@@ -4,20 +4,34 @@ import { upsertUser, setOTP, consumeOTP, createSession, getSession, deleteSessio
|
||||
|
||||
const SESSION_COOKIE = 'lv_session';
|
||||
const SESSION_DAYS = 30;
|
||||
const OTP_MINUTES = parseInt(import.meta.env.OTP_EXPIRES_MINUTES || '10');
|
||||
|
||||
// ── Mailer ────────────────────────────────────────────────────────────
|
||||
function getEnv(key: string, metaFallback?: any): string | undefined {
|
||||
if (typeof process !== 'undefined' && process.env && process.env[key]) {
|
||||
return process.env[key];
|
||||
}
|
||||
return metaFallback;
|
||||
}
|
||||
|
||||
const rawOtp = getEnv('OTP_EXPIRES_MINUTES', import.meta.env.OTP_EXPIRES_MINUTES) || '10';
|
||||
const OTP_MINUTES = isNaN(parseInt(rawOtp)) ? 10 : parseInt(rawOtp);
|
||||
|
||||
// ─ Mailer ────────────────────────────────────────────────────────────
|
||||
let _transport: nodemailer.Transporter | null = null;
|
||||
|
||||
function getTransport() {
|
||||
if (!_transport) {
|
||||
const smtpUser = getEnv('SMTP_USER', import.meta.env.SMTP_USER);
|
||||
const smtpPass = getEnv('SMTP_PASS', import.meta.env.SMTP_PASS);
|
||||
const rawPort = getEnv('SMTP_PORT', import.meta.env.SMTP_PORT) || '587';
|
||||
const smtpPort = isNaN(parseInt(rawPort)) ? 587 : parseInt(rawPort);
|
||||
|
||||
_transport = nodemailer.createTransport({
|
||||
host: import.meta.env.SMTP_HOST || 'localhost',
|
||||
port: parseInt(import.meta.env.SMTP_PORT || '587'),
|
||||
secure: import.meta.env.SMTP_SECURE === 'true',
|
||||
auth: import.meta.env.SMTP_USER ? {
|
||||
user: import.meta.env.SMTP_USER,
|
||||
pass: import.meta.env.SMTP_PASS,
|
||||
host: getEnv('SMTP_HOST', import.meta.env.SMTP_HOST) || 'localhost',
|
||||
port: smtpPort,
|
||||
secure: getEnv('SMTP_SECURE', import.meta.env.SMTP_SECURE) === 'true',
|
||||
auth: smtpUser ? {
|
||||
user: smtpUser,
|
||||
pass: smtpPass || '',
|
||||
} : undefined,
|
||||
tls: {
|
||||
rejectUnauthorized: false
|
||||
@@ -50,7 +64,7 @@ export async function sendOTP(email: string, lang: string = 'de'): Promise<{ ok:
|
||||
</div>`;
|
||||
|
||||
await getTransport().sendMail({
|
||||
from: import.meta.env.SMTP_FROM || 'Lebenslauf-App <noreply@localhost>',
|
||||
from: getEnv('SMTP_FROM', import.meta.env.SMTP_FROM) || 'Lebenslauf-App <noreply@localhost>',
|
||||
to: email,
|
||||
subject,
|
||||
html,
|
||||
|
||||
@@ -5,7 +5,7 @@ import { fileURLToPath } from 'url';
|
||||
import type { CV, CVData, CVSettings } from '../types';
|
||||
import { DEFAULT_DATA, DEFAULT_SETTINGS } from '../types';
|
||||
|
||||
const DB_PATH = import.meta.env.DB_PATH || join(process.cwd(), 'data', 'lebenslauf.db');
|
||||
const DB_PATH = process.env.DB_PATH || import.meta.env.DB_PATH || join(process.cwd(), 'data', 'lebenslauf.db');
|
||||
const dir = dirname(DB_PATH);
|
||||
if (!existsSync(dir)) mkdirSync(dir, { recursive: true });
|
||||
|
||||
|
||||
Reference in New Issue
Block a user