God Tier Hardening: Zod validation, SEO enforcement, connection pool monitoring
This commit is contained in:
51
src/pages/api/shim/health.ts
Normal file
51
src/pages/api/shim/health.ts
Normal file
@@ -0,0 +1,51 @@
|
||||
// API Route: GET /api/shim/health
|
||||
// Returns connection pool stats and database health
|
||||
|
||||
import type { APIRoute } from 'astro';
|
||||
import { getPoolStats, getDatabaseStats, getVacuumCandidates } from '@/lib/shim/pool';
|
||||
|
||||
export const GET: APIRoute = async ({ request }) => {
|
||||
try {
|
||||
// Token validation
|
||||
const authHeader = request.headers.get('Authorization');
|
||||
const token = authHeader?.replace('Bearer ', '');
|
||||
|
||||
const godToken = import.meta.env.GOD_MODE_TOKEN;
|
||||
if (godToken && token !== godToken) {
|
||||
return new Response(JSON.stringify({ error: 'Unauthorized' }), {
|
||||
status: 401,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
}
|
||||
|
||||
// Get health stats
|
||||
const poolStats = getPoolStats();
|
||||
const dbStats = await getDatabaseStats();
|
||||
const vacuumCandidates = await getVacuumCandidates();
|
||||
const needsVacuum = vacuumCandidates.length > 0 && vacuumCandidates[0].deadPercent > 20;
|
||||
|
||||
return new Response(JSON.stringify({
|
||||
timestamp: new Date().toISOString(),
|
||||
pool: poolStats,
|
||||
database: dbStats,
|
||||
vacuum: {
|
||||
recommended: needsVacuum,
|
||||
candidates: vacuumCandidates
|
||||
},
|
||||
status: poolStats.status
|
||||
}), {
|
||||
status: 200,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
|
||||
} catch (error: any) {
|
||||
console.error('Health check error:', error);
|
||||
return new Response(JSON.stringify({
|
||||
error: 'Health check failed',
|
||||
message: error.message
|
||||
}), {
|
||||
status: 500,
|
||||
headers: { 'Content-Type': 'application/json' }
|
||||
});
|
||||
}
|
||||
};
|
||||
Reference in New Issue
Block a user