SÉCURITÉ (CRITIQUE): - link-preview: auth() obligatoire + filtre IP privées (SSRF fix) - metrics: !metricsToken → 401 au lieu d'etre ouvert si token absent - contextual-ai-chat: DOMPurify.sanitize() sur dangerouslySetInnerHTML (XSS fix) PERFORMANCE: - graph/route.ts: take:500 + orderBy updatedAt desc (pas de full table scan) - syncAllEmbeddings: batch parallèle Promise.allSettled × 5 (pas séquentiel) - 80 console.log supprimés du code production BASE DE DONNÉES: - Note: index contentUpdatedAt + isPublic ajoutés au schema - DocumentChunk: commentaire index vectoriel HNSW (à exécuter manuellement)
44 lines
1.2 KiB
TypeScript
44 lines
1.2 KiB
TypeScript
import Redis from 'ioredis';
|
|
|
|
const globalForRedis = globalThis as unknown as { redis?: Redis };
|
|
|
|
const redis =
|
|
globalForRedis.redis ??
|
|
(process.env.REDIS_URL
|
|
? new Redis(process.env.REDIS_URL, {
|
|
lazyConnect: true,
|
|
retryStrategy(times) {
|
|
if (times > 10) {
|
|
console.error('[redis] Max retries exceeded, will retry in 30s');
|
|
return 30000;
|
|
}
|
|
return Math.min(times * 200, 2000);
|
|
},
|
|
maxRetriesPerRequest: 3,
|
|
})
|
|
: new Redis({
|
|
host: process.env.REDIS_HOST ?? 'localhost',
|
|
port: parseInt(process.env.REDIS_PORT ?? '6379'),
|
|
password: process.env.REDIS_PASSWORD,
|
|
lazyConnect: true,
|
|
retryStrategy(times) {
|
|
if (times > 10) {
|
|
console.error('[redis] Max retries exceeded, will retry in 30s');
|
|
return 30000;
|
|
}
|
|
return Math.min(times * 200, 2000);
|
|
},
|
|
maxRetriesPerRequest: 3,
|
|
}));
|
|
|
|
redis.on('error', (err) => {
|
|
console.error('[redis] Connection error:', err.message);
|
|
});
|
|
|
|
redis.on('connect', () => {
|
|
});
|
|
|
|
if (process.env.NODE_ENV !== 'production') globalForRedis.redis = redis;
|
|
|
|
export { redis };
|