@sehirapp/core-microservice
Version:
Modern mikroservis core paketi - MongoDB 6.7, Express API, Mongoose, PM2 cluster desteği
171 lines (137 loc) • 4.44 kB
JavaScript
export default {
apps: [
{
name: 'example-microservice',
script: './src/index.js',
// Cluster Mode Settings
instances: process.env.PM2_INSTANCES || 'max', // CPU çekirdeği kadar instance
exec_mode: 'cluster',
// Environment Variables
env: {
NODE_ENV: 'development',
PORT: 3000,
HOST: '0.0.0.0',
// Service Info
SERVICE_NAME: 'example-microservice',
SERVICE_VERSION: '1.0.0',
// Database
USE_MONGOOSE: 'true',
AUTO_CONNECT_DB: 'true',
// Security
ENABLE_API_KEY_AUTH: 'true',
ENABLE_RATE_LIMIT: 'true',
ENABLE_CORS: 'true',
ENABLE_SECURITY: 'true',
SKIP_API_AUTH: 'false',
// Logging
ENABLE_REQUEST_LOGGING: 'true',
REQUEST_LOG_LEVEL: 'info',
// PM2 Specific
PM2_GRACEFUL_TIMEOUT: '10000',
PM2_KILL_TIMEOUT: '5000'
},
env_production: {
NODE_ENV: 'production',
PORT: 3000,
HOST: '0.0.0.0',
// Service Info
SERVICE_NAME: 'example-microservice',
SERVICE_VERSION: '1.0.0',
// Database - Production
USE_MONGOOSE: 'true',
AUTO_CONNECT_DB: 'true',
MONGO_MAX_POOL_SIZE: '50',
MONGO_MIN_POOL_SIZE: '10',
// Security - Production
ENABLE_API_KEY_AUTH: 'true',
ENABLE_RATE_LIMIT: 'true',
ENABLE_CORS: 'true',
ENABLE_SECURITY: 'true',
TRUST_PROXY: 'true',
SKIP_API_AUTH: 'false',
// Rate Limiting - Production
RATE_LIMIT_WINDOW_MS: '900000', // 15 minutes
RATE_LIMIT_MAX: '10000', // 10000 requests per window
// Logging - Production
ENABLE_REQUEST_LOGGING: 'true',
REQUEST_LOG_LEVEL: 'warn',
// Performance - Production
REQUEST_SIZE_LIMIT: '50mb',
// MongoDB - Production
MONGO_TLS: 'true',
MONGO_SSL: 'true',
MONGO_WRITE_CONCERN: 'majority',
MONGO_READ_PREFERENCE: 'primaryPreferred'
},
env_staging: {
NODE_ENV: 'staging',
PORT: 3000,
HOST: '0.0.0.0',
// Service Info
SERVICE_NAME: 'example-microservice',
SERVICE_VERSION: '1.0.0',
// Database - Staging
USE_MONGOOSE: 'true',
AUTO_CONNECT_DB: 'true',
MONGO_MAX_POOL_SIZE: '20',
MONGO_MIN_POOL_SIZE: '5',
// Security - Staging
ENABLE_API_KEY_AUTH: 'true',
ENABLE_RATE_LIMIT: 'true',
ENABLE_CORS: 'true',
ENABLE_SECURITY: 'true',
SKIP_API_AUTH: 'false',
// Rate Limiting - Staging
RATE_LIMIT_WINDOW_MS: '900000',
RATE_LIMIT_MAX: '5000',
// Logging - Staging
ENABLE_REQUEST_LOGGING: 'true',
REQUEST_LOG_LEVEL: 'info'
},
// PM2 Settings
listen_timeout: 10000,
kill_timeout: 5000,
wait_ready: true,
// Auto Restart Settings
max_restarts: 10,
min_uptime: '10s',
max_memory_restart: '300M',
// Logging
log_file: './logs/pm2-combined.log',
out_file: './logs/pm2-out.log',
error_file: './logs/pm2-error.log',
log_date_format: 'YYYY-MM-DD HH:mm:ss Z',
// Advanced Settings
node_args: '--max-old-space-size=2048',
merge_logs: true,
// Health Monitoring
health_check_url: 'http://localhost:3000/health',
health_check_grace_period: 30000,
// Cron Jobs (opsiyonel)
cron_restart: process.env.PM2_CRON_RESTART || null,
// Watch & Ignore (development için)
watch: process.env.NODE_ENV === 'development' ? ['./src'] : false,
ignore_watch: [
'node_modules',
'logs',
'*.log',
'.git',
'.env*'
],
// Error Handling
autorestart: true,
watch_delay: 1000,
// Process Management
shutdown_with_message: true,
force: false,
// Custom PM2 Actions
post_update: ['npm install'],
// Environment için farklı instance sayıları
instances_by_env: {
development: 1,
staging: 2,
production: 'max'
}
}
]
};