1773ed5f95
Mirror to GitHub / mirror (push) Successful in 26s
Test and Lint / backend-test (push) Successful in 1m11s
continuous-integration/drone/push Build is passing
Test and Lint / frontend-test (push) Successful in 2m28s
Version and Release / version-bump (push) Successful in 32s
Version and Release / trigger-drone (push) Has been skipped
Original: feat: enhance security logging and ensure rate limit blocks are properly tracked - Add comprehensive logging for rate limit blocks with full request details - IP address (with proper proxy detection), user agent, headers, timestamps - Rate limit info (current count, limit, remaining, reset time) - Separate tracking for auth vs general endpoints - Enhance authentication failure logging - JWT validation failures with detailed error info - Admin auth attempts without token - Failed token validation with user context - All events include IP, path, method, user agent - Improve Winston logger configuration for production - Add automatic log rotation (10MB errors, 50MB combined) - Create separate security.log for auth/rate limit events - Ensure logs directory exists automatically - Add structured JSON format for log aggregation - Support container logging with LOG_TO_CONSOLE env var - Create comprehensive documentation - Security logging guide with examples - Monitoring recommendations - Configuration reference - Add test script to verify logging functionality All rate limit settings remain configurable via admin panel: - Window duration, max requests, auth limits - Skip authenticated requests option - Public endpoints only option 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
111 lines
3.0 KiB
JavaScript
111 lines
3.0 KiB
JavaScript
#!/usr/bin/env node
|
|
|
|
const { db } = require('../src/database/db');
|
|
const {
|
|
initializeTransporter,
|
|
processEmailQueue,
|
|
testEmailConnection
|
|
} = require('../src/services/emailProcessor');
|
|
const winston = require('winston');
|
|
|
|
// Create a simple console logger
|
|
const logger = winston.createLogger({
|
|
format: winston.format.simple(),
|
|
transports: [new winston.transports.Console()]
|
|
});
|
|
|
|
async function runEmailProcessor(runOnce = false) {
|
|
try {
|
|
logger.info('=== Starting Email Processor ===\n');
|
|
|
|
// Initialize transporter
|
|
logger.info('Initializing email transporter...');
|
|
await initializeTransporter();
|
|
|
|
// Test connection
|
|
logger.info('Testing email connection...');
|
|
const connectionOk = await testEmailConnection();
|
|
|
|
if (!connectionOk) {
|
|
logger.error('Email connection test failed! Check your SMTP configuration.');
|
|
logger.info('\nRequired environment variables:');
|
|
logger.info('- SMTP_HOST');
|
|
logger.info('- SMTP_PORT');
|
|
logger.info('- SMTP_USER');
|
|
logger.info('- SMTP_PASS');
|
|
logger.info('- SMTP_FROM');
|
|
process.exit(1);
|
|
}
|
|
|
|
logger.info('Email connection test successful!\n');
|
|
|
|
if (runOnce) {
|
|
// Process queue once
|
|
logger.info('Processing email queue once...');
|
|
await processEmailQueue();
|
|
logger.info('Email processing complete');
|
|
|
|
// Show final status
|
|
const pendingCount = await db('email_queue')
|
|
.where('status', 'pending')
|
|
.where('retry_count', '<', 3)
|
|
.count('* as count')
|
|
.first();
|
|
|
|
logger.info(`\nEmails still pending: ${pendingCount.count}`);
|
|
|
|
await db.destroy();
|
|
process.exit(0);
|
|
} else {
|
|
// Run continuously
|
|
logger.info('Starting continuous email processor...');
|
|
logger.info('Processing emails every 60 seconds. Press Ctrl+C to stop.\n');
|
|
|
|
// Process immediately
|
|
await processEmailQueue();
|
|
|
|
// Then every minute
|
|
setInterval(async () => {
|
|
try {
|
|
await processEmailQueue();
|
|
} catch (error) {
|
|
logger.error('Error processing email queue:', error);
|
|
}
|
|
}, 60000);
|
|
}
|
|
|
|
} catch (error) {
|
|
logger.error('Fatal error:', error);
|
|
await db.destroy();
|
|
process.exit(1);
|
|
}
|
|
}
|
|
|
|
// Handle graceful shutdown
|
|
process.on('SIGINT', async () => {
|
|
logger.info('\n\nShutting down email processor...');
|
|
await db.destroy();
|
|
process.exit(0);
|
|
});
|
|
|
|
// Check command line arguments
|
|
const args = process.argv.slice(2);
|
|
const runOnce = args.includes('--once') || args.includes('-o');
|
|
|
|
if (args.includes('--help') || args.includes('-h')) {
|
|
console.log(`
|
|
Email Processor Runner
|
|
|
|
Usage: node run-email-processor.js [options]
|
|
|
|
Options:
|
|
--once, -o Process the email queue once and exit
|
|
--help, -h Show this help message
|
|
|
|
By default, the processor runs continuously, checking for emails every 60 seconds.
|
|
`);
|
|
process.exit(0);
|
|
}
|
|
|
|
// Run the processor
|
|
runEmailProcessor(runOnce); |