story-generator/src/pages/api/health.ts
Lucas Santana cc23c83c05 feat: adiciona redis e healthcheck
- Implementa cliente Redis com retry e cache
- Adiciona healthcheck da API
- Configura tipagem para Next.js API routes
- Implementa cache de histórias
- Adiciona tratamento de erros robusto
- Configura monitoramento de conexões
- Otimiza performance com cache distribuído
2024-12-25 13:55:03 -03:00

22 lines
776 B
TypeScript

import redis from '@/lib/redis';
import { supabase } from '@/lib/supabase';
export default async function handler(_: any, res: { status: (arg0: number) => { (): any; new(): any; json: { (arg0: { status: string; error?: any; }): void; new(): any; }; }; }) {
try {
// Verifica conexão com Redis
await redis.ping();
// Verifica conexão com Supabase
const { data, error } = await supabase.from('stories').select('id').limit(1);
if (error) throw error;
res.status(200).json({ status: 'healthy' });
} catch (error: unknown) {
if (error instanceof Error) {
res.status(500).json({ status: 'unhealthy', error: error.message });
} else {
res.status(500).json({ status: 'unhealthy', error: 'Erro desconhecido' });
}
}
}