fix: enhance Redis connection handling and improve error logging in API startup
This commit is contained in:
@@ -11,9 +11,8 @@ import { showRoutes } from 'hono/dev';
|
||||
async function startServer() {
|
||||
console.log('Starting server on port:', API_PORT);
|
||||
|
||||
// Connect to Redis before starting the server
|
||||
// Connect to Redis (non-blocking: API starts even if Redis fails)
|
||||
await connectRedis();
|
||||
console.log('Redis connected successfully');
|
||||
|
||||
serve({ fetch: app.fetch, port: API_PORT });
|
||||
|
||||
|
||||
@@ -23,9 +23,17 @@ client.on('reconnecting', () => {
|
||||
let isConnected = false;
|
||||
|
||||
export async function connectRedis(): Promise<void> {
|
||||
if (!isConnected) {
|
||||
if (!env.REDIS_URL) {
|
||||
console.warn('REDIS_URL not set, Redis features disabled');
|
||||
return;
|
||||
}
|
||||
if (isConnected) return;
|
||||
try {
|
||||
await client.connect();
|
||||
isConnected = true;
|
||||
} catch (error) {
|
||||
console.error('Redis connection failed, API will run without Redis:', error);
|
||||
// Don't throw - allow API to start; rate limiting and caching will degrade gracefully
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user