Files
hasher/app/api/health/route.ts
2025-12-04 00:58:40 +01:00

45 líneas
1.2 KiB
TypeScript

import { NextResponse } from 'next/server';
import { esClient, INDEX_NAME } from '@/lib/elasticsearch';
export async function GET() {
try {
// Check Elasticsearch connection
const health = await esClient.cluster.health({});
// Check if index exists
const indexExists = await esClient.indices.exists({ index: INDEX_NAME });
// Get index stats if exists
let stats = null;
if (indexExists) {
const statsResponse = await esClient.indices.stats({ index: INDEX_NAME });
stats = {
documentCount: statsResponse._all?.primaries?.docs?.count || 0,
indexSize: statsResponse._all?.primaries?.store?.size_in_bytes || 0
};
}
return NextResponse.json({
status: 'ok',
elasticsearch: {
cluster: health.cluster_name,
status: health.status,
},
index: {
exists: indexExists,
name: INDEX_NAME,
stats
}
});
} catch (error) {
console.error('Health check error:', error);
return NextResponse.json(
{
status: 'error',
error: error instanceof Error ? error.message : 'Unknown error'
},
{ status: 503 }
);
}
}