267e80e2ec
- Refactor server initialization to separate concerns and improve error handling. - Implement centralized environment validation using Zod. - Introduce database, Redis, and queue lifecycle management. - Add health check endpoints for liveness and readiness. - Enhance error handling middleware for better response structure. - Implement rate limiting for API endpoints. - Add request ID middleware for traceability. - Create Sequelize CLI configuration and baseline migration for schema management. - Establish CI workflow with Gitea for testing and syntax checks. - Document foundational changes and migration strategy in PHASE_0_FOUNDATION_STABILIZATION.md. - Add Docker Compose configuration for local development and testing. - Implement unit and integration tests for critical functionality.
49 lines
1.1 KiB
JavaScript
49 lines
1.1 KiB
JavaScript
/**
|
|
* Copyright (c) 2026 Niolla
|
|
* All rights reserved.
|
|
*
|
|
* This source code is proprietary and confidential.
|
|
* Unauthorized copying, modification, distribution, or use
|
|
* of this file, via any medium, is strictly prohibited.
|
|
*/
|
|
|
|
// app/config/redis.config.js
|
|
|
|
const { Redis } = require("ioredis");
|
|
|
|
const createRedisConnection = (options = {}) => {
|
|
const redis = new Redis({
|
|
host: process.env.REDIS_HOST || "redis",
|
|
port: process.env.REDIS_PORT || 6379,
|
|
password: process.env.REDIS_PASSWORD,
|
|
maxRetriesPerRequest: null,
|
|
enableReadyCheck: false,
|
|
lazyConnect: options.lazyConnect ?? true,
|
|
});
|
|
|
|
// Connection events
|
|
redis.on("connect", () => {
|
|
console.log("Redis connecting...");
|
|
});
|
|
|
|
redis.on("ready", () => {
|
|
console.log("Redis connected and ready!");
|
|
});
|
|
|
|
redis.on("error", (err) => {
|
|
console.error("Redis error:", err.message);
|
|
});
|
|
|
|
redis.on("close", () => {
|
|
console.warn("Redis connection closed");
|
|
});
|
|
|
|
redis.on("reconnecting", () => {
|
|
console.log("Redis reconnecting...");
|
|
});
|
|
|
|
return redis;
|
|
};
|
|
|
|
module.exports = createRedisConnection;
|