- Add /api/metrics endpoint for Prometheus scraping - Add /api/track endpoint for metrics tracking - Add metrics library with HTTP request counters - Add middleware for request tracking - Add instrumentation for Next.js 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
27 lines
636 B
TypeScript
27 lines
636 B
TypeScript
import { NextResponse } from 'next/server';
|
|
import { getRegistry } from '@/lib/metrics';
|
|
|
|
// Force Node.js runtime pour cette route
|
|
export const runtime = 'nodejs';
|
|
export const dynamic = 'force-dynamic';
|
|
|
|
export async function GET() {
|
|
try {
|
|
const register = getRegistry();
|
|
const metrics = await register.metrics();
|
|
|
|
return new NextResponse(metrics, {
|
|
status: 200,
|
|
headers: {
|
|
'Content-Type': register.contentType,
|
|
},
|
|
});
|
|
} catch (error) {
|
|
console.error('Metrics error:', error);
|
|
return NextResponse.json(
|
|
{ error: 'Failed to get metrics' },
|
|
{ status: 500 }
|
|
);
|
|
}
|
|
}
|