Skip to main content

Configuration Guide

Environment Variables

Backend Configuration

# .env
NODE_ENV=production
PORT=3000
MONGODB_URI=mongodb://localhost:27017/eyenet
JWT_SECRET=your_secure_jwt_secret
LOG_LEVEL=info
CORS_ORIGIN=https://eyenet.example.com

Frontend Configuration

# .env.production
NEXT_PUBLIC_API_URL=https://api.eyenet.example.com
NEXT_PUBLIC_WS_URL=wss://api.eyenet.example.com

Database Configuration

MongoDB Settings

// config/database.ts
export const databaseConfig = {
url: process.env.MONGODB_URI,
options: {
useNewUrlParser: true,
useUnifiedTopology: true,
maxPoolSize: 10,
serverSelectionTimeoutMS: 5000,
socketTimeoutMS: 45000,
}
};

Indexes

// Create indexes for better performance
db.devices.createIndex({ "name": 1 });
db.metrics.createIndex({ "timestamp": -1 });
db.logs.createIndex({ "level": 1, "timestamp": -1 });

Network Controllers Configuration

OpenDaylight Controller

// config/controllers/opendaylight.ts
export const openDaylightConfig = {
baseUrl: process.env.OPENDAYLIGHT_URL || 'http://localhost:8181',
auth: {
username: process.env.OPENDAYLIGHT_USER || 'admin',
password: process.env.OPENDAYLIGHT_PASS || 'admin'
},
timeout: 5000,
retryAttempts: 3
};

pfSense Configuration

// config/controllers/pfsense.ts
export const pfSenseConfig = {
baseUrl: process.env.PFSENSE_URL,
apiKey: process.env.PFSENSE_API_KEY,
timeout: 3000,
validateCert: process.env.NODE_ENV === 'production'
};

MikroTik Configuration

// config/controllers/mikrotik.ts
export const mikroTikConfig = {
host: process.env.MIKROTIK_HOST,
port: parseInt(process.env.MIKROTIK_PORT || '8728'),
username: process.env.MIKROTIK_USER,
password: process.env.MIKROTIK_PASS,
timeout: 5000
};

Security Configuration

JWT Settings

// config/auth.ts
export const authConfig = {
jwt: {
secret: process.env.JWT_SECRET,
expiresIn: '24h',
algorithm: 'HS256'
},
passwordHash: {
saltRounds: 10
}
};

CORS Configuration

// config/cors.ts
export const corsConfig = {
origin: process.env.CORS_ORIGIN,
methods: ['GET', 'POST', 'PUT', 'DELETE', 'OPTIONS'],
allowedHeaders: ['Content-Type', 'Authorization'],
exposedHeaders: ['Content-Range', 'X-Content-Range'],
credentials: true,
maxAge: 86400
};

Logging Configuration

Winston Logger

// config/logger.ts
import winston from 'winston';

export const loggerConfig = {
level: process.env.LOG_LEVEL || 'info',
format: winston.format.combine(
winston.format.timestamp(),
winston.format.json()
),
transports: [
new winston.transports.Console(),
new winston.transports.File({
filename: 'logs/error.log',
level: 'error'
}),
new winston.transports.File({
filename: 'logs/combined.log'
})
]
};

Cache Configuration

Redis Settings

// config/cache.ts
export const redisConfig = {
host: process.env.REDIS_HOST || 'localhost',
port: parseInt(process.env.REDIS_PORT || '6379'),
password: process.env.REDIS_PASSWORD,
db: parseInt(process.env.REDIS_DB || '0'),
keyPrefix: 'eyenet:',
ttl: 3600 // 1 hour
};

Rate Limiting

// config/rateLimit.ts
export const rateLimitConfig = {
windowMs: 15 * 60 * 1000, // 15 minutes
max: 100, // limit each IP to 100 requests per windowMs
message: 'Too many requests from this IP, please try again later',
standardHeaders: true,
legacyHeaders: false
};

Monitoring Configuration

Metrics Collection

// config/metrics.ts
export const metricsConfig = {
interval: 60000, // 1 minute
retention: {
raw: '7d', // 7 days
hourly: '30d', // 30 days
daily: '365d' // 1 year
},
alertThresholds: {
cpu: 80, // 80% utilization
memory: 85, // 85% utilization
disk: 90 // 90% utilization
}
};

Backup Configuration

// config/backup.ts
export const backupConfig = {
mongodb: {
schedule: '0 0 * * *', // Daily at midnight
retention: 7, // Keep 7 days of backups
path: '/backups/mongodb'
},
logs: {
schedule: '0 0 * * 0', // Weekly on Sunday
retention: 4, // Keep 4 weeks of logs
path: '/backups/logs'
}
};

Email Configuration

// config/email.ts
export const emailConfig = {
smtp: {
host: process.env.SMTP_HOST,
port: parseInt(process.env.SMTP_PORT || '587'),
secure: process.env.SMTP_SECURE === 'true',
auth: {
user: process.env.SMTP_USER,
pass: process.env.SMTP_PASS
}
},
from: {
name: 'EyeNet System',
email: 'system@eyenet.example.com'
},
templates: {
path: 'templates/email',
engine: 'handlebars'
}
};

Feature Flags

// config/features.ts
export const featureFlags = {
enableML: process.env.ENABLE_ML === 'true',
enableRealTimeMonitoring: true,
enableAutomation: process.env.ENABLE_AUTOMATION === 'true',
enableAdvancedAnalytics: process.env.ENABLE_ADVANCED_ANALYTICS === 'true'
};